UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

56 lines (55 loc) 2.48 kB
import { EntityMetadata } from '../model/entity-metadata.js'; export function BeforeInsert() { return (target, propertyKey) => { if (typeof propertyKey !== 'string') throw new Error('You can define a Column for only string properties'); const model = EntityMetadata.define(target.constructor); const fn = target.constructor.prototype[propertyKey]; EntityMetadata.addEventListener(model, 'before-insert', fn); }; } export function BeforeUpdate() { return (target, propertyKey) => { if (typeof propertyKey !== 'string') throw new Error('You can define a Column for only string properties'); const model = EntityMetadata.define(target.constructor); const fn = target.constructor.prototype[propertyKey]; EntityMetadata.addEventListener(model, 'before-update', fn); }; } export function BeforeDestroy() { return (target, propertyKey) => { if (typeof propertyKey !== 'string') throw new Error('You can define a Column for only string properties'); const model = EntityMetadata.define(target.constructor); const fn = target.constructor.prototype[propertyKey]; EntityMetadata.addEventListener(model, 'before-destroy', fn); }; } export function AfterInsert() { return (target, propertyKey) => { if (typeof propertyKey !== 'string') throw new Error('You can define a Column for only string properties'); const model = EntityMetadata.define(target.constructor); const fn = target.constructor.prototype[propertyKey]; EntityMetadata.addEventListener(model, 'after-insert', fn); }; } export function AfterUpdate() { return (target, propertyKey) => { if (typeof propertyKey !== 'string') throw new Error('You can define a Column for only string properties'); const model = EntityMetadata.define(target.constructor); const fn = target.constructor.prototype[propertyKey]; EntityMetadata.addEventListener(model, 'after-update', fn); }; } export function AfterDestroy() { return (target, propertyKey) => { if (typeof propertyKey !== 'string') throw new Error('You can define a Column for only string properties'); const model = EntityMetadata.define(target.constructor); const fn = target.constructor.prototype[propertyKey]; EntityMetadata.addEventListener(model, 'after-destroy', fn); }; }