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.

68 lines (49 loc) 1.24 kB
import { BaseEntity, ManyToMany, Collection, Entity, Formula, JsonType, OneToOne, PrimaryKey, Property, OptionalProps, } from '@mikro-orm/core'; import { FooBaz2 } from './FooBaz2'; import { Test2 } from './Test2'; @Entity() export class FooBar2 extends BaseEntity { [OptionalProps]?: 'version'; @PrimaryKey() id!: number; @Property() name!: string; @Property({ name: 'name with space', nullable: true }) nameWithSpace?: string; @OneToOne({ orphanRemoval: true, nullable: true }) baz?: FooBaz2; @OneToOne({ nullable: true }) fooBar?: FooBar2; @Property({ version: true, length: 0 }) version!: Date; @Property({ nullable: true }) blob?: Buffer; @Property({ nullable: true }) blob2?: Uint8Array; @Property({ type: 'number[]', nullable: true }) array?: number[]; @Property({ type: JsonType, nullable: true }) objectProperty?: { foo: string; bar: number } | any; @Formula(`(select 123)`) random?: number; @Formula(`(select 456)`, { lazy: true }) lazyRandom?: number; @ManyToMany(() => Test2, t => t.bars) tests = new Collection<Test2>(this); static create(name: string) { const bar = new FooBar2(); bar.name = name; return bar; } }