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.
43 lines (31 loc) • 810 B
text/typescript
import { ObjectId } from 'bson';
import {
BeforeCreate,
PrimaryKey,
Property,
SerializedPrimaryKey,
BaseEntity as MikroBaseEntity,
OptionalProps,
PrimaryKeyProp,
} from '@mikro-orm/core';
export type BaseEntityOptional = 'updatedAt' | 'hookTest';
export abstract class BaseEntity<T extends object, Optional extends keyof T = never> extends MikroBaseEntity {
[OptionalProps]?: BaseEntityOptional | Optional;
[PrimaryKeyProp]?: 'id' | '_id';
()
_id!: ObjectId;
()
id!: string;
()
createdAt? = new Date();
({ onUpdate: () => new Date() })
updatedAt = new Date();
()
foo?: string;
({ persist: false })
hookTest = false;
()
baseBeforeCreate() {
this.hookTest = true;
}
}