本文整理匯總了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;
}
示例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));
}
示例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();
}
示例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;
}
}
示例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();
}
示例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!;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}