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.
63 lines (48 loc) • 1.22 kB
text/typescript
import {
Collection,
Entity,
ManyToOne,
OneToMany,
MikroORM,
PrimaryKey,
Property,
OptionalProps,
} from '@mikro-orm/core';
import { BetterSqliteDriver } from '@mikro-orm/better-sqlite';
()
class TestRunEntity {
()
id!: number;
(() => TestCaseEntity, e => e.testRun)
cases = new Collection<TestCaseEntity>(this);
}
()
class TestCaseEntity {
[OptionalProps]?: 'testRun';
()
id!: number;
()
title!: string;
(() => TestRunEntity)
testRun!: TestRunEntity;
}
let orm: MikroORM<BetterSqliteDriver>;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [TestCaseEntity],
dbName: ':memory:',
driver: BetterSqliteDriver,
});
await orm.schema.createSchema();
});
afterAll(() => orm.close(true));
// should run around 50-100ms
test('perf: create large 1:m collection', async () => {
console.time('perf: create large 1:m collection (10k entities)');
const entity = orm.em.create(TestRunEntity, {
cases: Array(10_000).fill(undefined).map((_, index) => ({
title: `Test Case #${index}`,
})),
});
console.timeEnd('perf: create large 1:m collection (10k entities)');
});