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.
54 lines (39 loc) • 1.1 kB
text/typescript
import { Collection, Entity, ManyToOne, MikroORM, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
import { MySqlDriver } from '@mikro-orm/mysql';
()
export class Author {
({ columnType: 'mediumint' })
id!: number;
()
name!: string;
(() => Book, book => book.author)
books = new Collection<Book>(this);
}
()
export class Book {
({ columnType: 'mediumint' })
bookId!: number;
()
title!: string;
(() => Author)
author!: Author;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Author, Book],
dbName: `mikro_orm_test_gh_3230`,
driver: MySqlDriver,
port: 3308,
});
await orm.schema.ensureDatabase();
await orm.schema.dropSchema();
});
afterAll(() => orm.close(true));
test('mediumint column type in mysql as FK', async () => {
const sql = await orm.schema.getCreateSchemaSQL();
expect(sql).toMatchSnapshot();
await orm.schema.execute(sql);
const diff = await orm.schema.getUpdateSchemaSQL();
expect(diff).toBe('');
});