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) • 1.22 kB
text/typescript
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/sqlite';
()
class Sea {
()
id!: number;
(() => Fish, ({ sea }) => sea)
fishes = new Collection<Fish>(this);
}
()
class Fish {
()
id!: number;
(() => Sea)
sea!: Sea;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Sea, Fish],
dbName: ':memory:',
});
await orm.getSchemaGenerator().createSchema();
});
beforeEach(() => orm.schema.clearDatabase());
afterAll(() => orm.close(true));
test('when persisting the whole model, it is slow', async () => {
const mediterranean = new Sea();
const groupers = Array.from({ length: 10_000 }).map(() => new Fish());
mediterranean.fishes.add(groupers);
orm.em.persist(mediterranean);
await orm.em.flush();
});
test('when flushing the container before the contained data, it is fast', async () => {
const mediterranean = new Sea();
await orm.em.persistAndFlush(mediterranean);
const groupers = Array.from({ length: 10_000 }).map(() => new Fish());
mediterranean.fishes.add(groupers);
await orm.em.flush();
});