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
text/typescript
import { Entity, LoadStrategy, OneToMany, ManyToOne, Collection, PrimaryKey } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/sqlite';
()
class BidEntity {
()
id!: bigint;
('ItemEntity', {
serializer: value => value.id,
serializedName: 'itemId',
})
item: any;
}
()
class ItemEntity {
()
id!: bigint;
('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();
});