UNPKG

undeexcepturi

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

53 lines (40 loc) 979 B
import { Entity, LoadStrategy, OneToMany, ManyToOne, Collection, PrimaryKey } from '@mikro-orm/core'; import { MikroORM } from '@mikro-orm/sqlite'; @Entity() class BidEntity { @PrimaryKey() id!: bigint; @ManyToOne('ItemEntity', { serializer: value => value.id, serializedName: 'itemId', }) item: any; } @Entity() class ItemEntity { @PrimaryKey() id!: bigint; @OneToMany('BidEntity', 'item', { orphanRemoval: true, strategy: LoadStrategy.JOINED, mappedBy: 'item', }) bids = new Collection<BidEntity>(this); } let orm: MikroORM; beforeAll(async () => { orm = await MikroORM.init({ dbName: ':memory:', entities: [BidEntity, ItemEntity], }); await orm.schema.refreshDatabase(); }); afterAll(() => orm.close(true)); test('select big int', async () => { await orm.em .createQueryBuilder(ItemEntity, 'item') .select('*') .leftJoinAndSelect('item.bids', 'bids') .limit(10) .getResultAndCount(); });