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.

105 lines (89 loc) 1.86 kB
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'; import { MikroORM } from '@mikro-orm/sqlite'; @Entity() class MyEntity { @PrimaryKey() id?: number; @Property({ type: 'json' }) postIds!: number[]; } let orm: MikroORM; beforeAll(async () => { orm = await MikroORM.init({ entities: [MyEntity], dbName: `:memory:`, }); await orm.schema.refreshDatabase(); }); afterAll(async () => { await orm.close(true); }); beforeEach(async () => { await orm.schema.clearDatabase(); }); test('insertMany array of numbers to JSON', async () => { await orm.em.insertMany(MyEntity, [ { id: 1, postIds: [10, 11, 12], }, { id: 2, postIds: [20, 21], }, ]); }); test('insertMany entities array of numbers to JSON', async () => { await orm.em.insertMany([ orm.em.create(MyEntity, { id: 1, postIds: [10, 11, 12], }), orm.em.create(MyEntity, { id: 2, postIds: [20, 21], }), ]); }); test('upsertMany array of numbers to JSON', async () => { await orm.em.upsertMany(MyEntity, [ { id: 1, postIds: [10, 11, 12], }, { id: 2, postIds: [20, 21], }, ]); }); test('upsert array of numbers to JSON', async () => { await orm.em.upsert(MyEntity, { id: 1, postIds: [10, 11, 12], }); }); test('insert array of numbers to JSON', async () => { await orm.em.insert(MyEntity, { id: 1, postIds: [10, 11, 12], }); }); test('flush one array of numbers to JSON', async () => { orm.em.create(MyEntity, { id: 1, postIds: [10, 11, 12], }); await orm.em.flush(); }); test('flush many array of numbers to JSON', async () => { orm.em.create(MyEntity, { id: 1, postIds: [10, 11, 12], }); orm.em.create(MyEntity, { id: 2, postIds: [20, 21], }); await orm.em.flush(); });