UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

25 lines (24 loc) 794 B
import { Entity } from './decorators/entity.decorator.js'; import { REPOSITORY_KEY } from './orm.const.js'; export class BaseEntity { constructor(partial) { const fields = Entity.getColumnFieldNames(Object.getPrototypeOf(this).constructor); if (fields && partial) { for (const k of fields) if (partial[k] !== undefined) this[k] = partial[k]; } } async destroy() { const repo = this[REPOSITORY_KEY]; return !!(repo && repo.destroy(this)); } async exists() { const repo = this[REPOSITORY_KEY]; return !!(repo && repo.exists(this)); } toJSON() { // this method is a placeholder and will be overwritten by declareEntity() method return this; } }