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.
51 lines (38 loc) • 1.47 kB
text/typescript
import { Embeddable, Embedded, Entity, MikroORM, PrimaryKey, Property } from '@mikro-orm/sqlite';
import { mockLogger } from '../../helpers';
()
class Address {
()
country!: string;
}
()
class User {
()
id!: number;
({ unique: true })
email!: string;
(() => Address)
address!: Address;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
dbName: ':memory:',
entities: [User],
});
await orm.schema.createSchema();
});
afterAll(async () => {
await orm.close(true);
});
test('cursor pagination', async () => {
const mock = mockLogger(orm);
await orm.em.find(User, {}, { first: 100, orderBy: { email: 'ASC' } });
await orm.em.find(User, {}, { limit: 100, orderBy: { email: 'ASC' } });
await orm.em.find(User, {}, { first: 100, orderBy: { address: { country: 'ASC' } } });
await orm.em.find(User, {}, { limit: 100, orderBy: { address: { country: 'ASC' } } });
expect(mock.mock.calls[0][0]).toMatch('select `u0`.* from `user` as `u0` order by `u0`.`email` asc limit 100');
expect(mock.mock.calls[1][0]).toMatch('select `u0`.* from `user` as `u0` order by `u0`.`email` asc limit 100');
expect(mock.mock.calls[2][0]).toMatch('select `u0`.* from `user` as `u0` order by `u0`.`address_country` asc limit 100');
expect(mock.mock.calls[3][0]).toMatch('select `u0`.* from `user` as `u0` order by `u0`.`address_country` asc limit 100');
});