當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript typeorm.getManager函數代碼示例

本文整理匯總了TypeScript中typeorm.getManager函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getManager函數的具體用法?TypeScript getManager怎麽用?TypeScript getManager使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了getManager函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: addPlayerToTeam

  public async addPlayerToTeam(player: Player, team: Team): Promise<Player> {
    player.teams = [team];

    await getManager().getRepository(Player).save(player);
    const sharePromises: Array<Promise<Share>> = [];

    for (const share of player.shares) {
      share.player = player;
      player.shares.push(share);
      sharePromises.push(getManager().getRepository(Share).save(share));
    }

    await Promise.all(sharePromises);
    return player;
  }
開發者ID:snickroger,項目名稱:FantasyMovieLeague,代碼行數:15,代碼來源:sql.ts

示例2: getAllSeasonsForMenu

  public async getAllSeasonsForMenu(): Promise<SeasonMenuItem[]> {
    const season = await getManager().getRepository(Season).createQueryBuilder("season")
      .orderBy("season.id", "DESC")
      .getMany();

    return season.map((s) => new SeasonMenuItem(s.name, s.slug));
  }
開發者ID:snickroger,項目名稱:FantasyMovieLeague,代碼行數:7,代碼來源:sql.ts

示例3: updateRatingForMovie

 public async updateRatingForMovie(movie: Movie, rating: number): Promise<void> {
   await getManager().getRepository(Movie).createQueryBuilder("movies")
     .update()
     .set({ rating })
     .where({ id: movie.id })
     .execute();
 }
開發者ID:snickroger,項目名稱:FantasyMovieLeague,代碼行數:7,代碼來源:sql.ts

示例4: createUser

    public static async createUser (ctx: BaseContext) {

        // get a user repository to perform operations with user
        const userRepository: Repository<User> = getManager().getRepository(User);

        // build up entity user to be saved
        const userToBeSaved: User = new User();
        userToBeSaved.name = ctx.request.body.name;
        userToBeSaved.email = ctx.request.body.email;

        // validate user entity
        const errors: ValidationError[] = await validate(userToBeSaved); // errors is an array of validation errors

        if (errors.length > 0) {
            // return bad request status code and errors array
            ctx.status = 400;
            ctx.body = errors;
        } else {
            // save the user contained in the POST body
            const user = await userRepository.save(userToBeSaved);
            // return created status code and updated user
            ctx.status = 201;
            ctx.body = user;
        }
    }
開發者ID:ryanwild,項目名稱:node-typescript-koa-rest,代碼行數:25,代碼來源:user.ts

示例5: getMovie

 public async getMovie(id: number, team: Team): Promise<Movie | undefined> {
   return await getManager().getRepository(Movie).createQueryBuilder("movie")
     .leftJoinAndSelect("movie.earnings", "earnings")
     .leftJoinAndSelect("movie.shares", "shares")
     .where("movie.id = :id", { id })
     .andWhere("shares.playerId IN (:...players)", { players: team.players.map((p) => p.id) })
     .getOne();
 }
開發者ID:snickroger,項目名稱:FantasyMovieLeague,代碼行數:8,代碼來源:sql.ts

示例6: getTeam

  public async getTeam(id: number): Promise<Team> {
    const team = await getManager().getRepository(Team).createQueryBuilder("team")
      .innerJoinAndSelect("team.players", "players")
      .innerJoinAndSelect("team.season", "season")
      .where("team.id = :id", { id })
      .getOne();

    return team!;
  }
開發者ID:snickroger,項目名稱:FantasyMovieLeague,代碼行數:9,代碼來源:sql.ts

示例7: postGetAllAction

export async function postGetAllAction(context: Context) {

    // get a post repository to perform operations with post
    const postRepository = getManager().getRepository(Post);

    // load all posts
    const posts = await postRepository.find();

    // return loaded posts
    context.body = posts;
}
開發者ID:willchapin,項目名稱:typescript-koa-example,代碼行數:11,代碼來源:PostGetAllAction.ts

示例8: getUsers

    public static async getUsers (ctx: BaseContext) {

        // get a user repository to perform operations with user
        const userRepository: Repository<User> = getManager().getRepository(User);

        // load all users
        const users: User[] = await userRepository.find();

        // return loaded users
        ctx.body = users;
    }
開發者ID:ryanwild,項目名稱:node-typescript-koa-rest,代碼行數:11,代碼來源:user.ts

示例9: getSelectedSeason

  public async getSelectedSeason(seasonSlug: string | undefined): Promise<Season | undefined> {
    let slug: string;
    if (seasonSlug === undefined) {
      const maxSeason = await getManager().getRepository(Season).createQueryBuilder("season")
        .orderBy("id", "DESC")
        .getOne();
      slug = maxSeason!.slug;
    } else {
      slug = seasonSlug;
    }

    const season = await getManager().getRepository(Season).createQueryBuilder("season")
      .leftJoinAndSelect("season.teams", "teams")
      .leftJoinAndSelect("season.movies", "movies")
      .leftJoinAndSelect("season.urls", "urls")
      .leftJoinAndSelect("movies.earnings", "earnings")
      .leftJoinAndSelect("movies.shares", "shares")
      .where("season.slug LIKE :slug", { slug })
      .getOne();

    return season;
  }
開發者ID:snickroger,項目名稱:FantasyMovieLeague,代碼行數:22,代碼來源:sql.ts

示例10: postSaveAction

export async function postSaveAction(context: Context) {

    // get a post repository to perform operations with post
    const postRepository = getManager().getRepository(Post);

    // create a real post object from post json object sent over http
    const newPost = postRepository.create(context.request.body);

    // save received post
    await postRepository.save(newPost);

    // return saved post back
    context.body = newPost;
}
開發者ID:willchapin,項目名稱:typescript-koa-example,代碼行數:14,代碼來源:PostSaveAction.ts


注:本文中的typeorm.getManager函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。