当前位置: 首页>>代码示例>>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;未经允许,请勿转载。