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.
77 lines (56 loc) • 1.62 kB
text/typescript
import { ObjectId } from 'bson';
import {
ArrayType,
Entity,
Index,
EagerProps,
JsonType,
OneToOne,
PrimaryKey,
Property,
SerializedPrimaryKey, OptionalProps,
} from '@mikro-orm/core';
import { FooBaz } from './FooBaz';
()
({ options: [
{ name: 'text', str: 'text', baz: 1 },
{ weights: { name: 10, str: 5 } },
] })
export default class FooBar {
[EagerProps]?: 'baz';
[OptionalProps]?: 'meta';
()
_id!: ObjectId;
()
id!: string;
()
name!: string;
({ entity: () => FooBaz, eager: true, orphanRemoval: true, nullable: true, serializedName: 'fooBaz', serializer: value => `FooBaz id: ${value.id}` })
baz!: FooBaz | null;
(() => FooBar, undefined, { nullable: true })
fooBar?: FooBar;
({ nullable: true })
blob?: Buffer;
({ nullable: true })
blob2?: Uint8Array;
({ type: new ArrayType(i => +i), nullable: true })
array?: number[];
({ nullable: true })
num?: number;
({ nullable: true })
str?: string;
({ type: JsonType, nullable: true })
object?: { foo: string; bar: number } | any;
({ onCreate: (bar: FooBar) => bar.meta.onCreateCalled = true })
onCreateTest?: boolean;
({ onCreate: (bar: FooBar) => bar.meta.onUpdateCalled = true })
onUpdateTest?: boolean;
({ nullable: true })
tenant?: number;
readonly meta = { onCreateCalled: false, onUpdateCalled: false };
static create(name: string) {
const bar = new FooBar();
bar.name = name;
return bar;
}
}