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.
55 lines (41 loc) • 1.08 kB
text/typescript
import { Collection, Entity, Enum, ManyToOne, MikroORM, OneToMany, PrimaryKey, Property } from '@mikro-orm/sqlite';
class Book {
id!: number;
children = new Collection<Author>(this);
}
enum AuthorType {
Apple = 'Apple',
Banana = 'Banana',
}
class Author {
id!: string;
type!: AuthorType;
book!: Book;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Author, Book],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(async () => {
await orm.close(true);
});
test(`GH issue 3053`, async () => {
const sql = orm.em.qb(Book).where({
children: {
id: '123ABC',
type: AuthorType.Apple,
},
}).getFormattedQuery();
expect(sql).toBe("select `b0`.* from `book` as `b0` left join `author` as `a1` on `b0`.`id` = `a1`.`book_id` where (`a1`.`id`, `a1`.`type`) in (('123ABC', 'Apple'))");
});