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.

45 lines (34 loc) 1.1 kB
import { Entity, PrimaryKey, Property, SimpleLogger } from '@mikro-orm/core'; import { MikroORM } from '@mikro-orm/postgresql'; import { mockLogger } from '../../bootstrap'; @Entity() class Book { @PrimaryKey() id!: number; @Property() title!: string; } @Entity({ expression: 'select title from book' }) class BookSimple { @Property() title!: string; } let orm: MikroORM; beforeAll(async () => { orm = await MikroORM.init({ dbName: 'virtual_entities', entities: [Book, BookSimple], loggerFactory: options => new SimpleLogger(options), }); await orm.schema.refreshDatabase(); }); beforeEach(async () => orm.schema.clearDatabase()); afterAll(async () => orm.close(true)); test('virtual entities (postgres)', async () => { const mock = mockLogger(orm); await orm.em.findAndCount(BookSimple, {}, { orderBy: { title: 1 } }); expect(mock.mock.calls.map(r => r[0]).sort()).toEqual([ `[query] select * from (select title from book) as "b0" order by "b0"."title" asc`, `[query] select count(*) as count from (select title from book) as "b0"`, ]); });