@sqb/connect
Version:
Multi-dialect database connection framework written with TypeScript
29 lines (28 loc) • 995 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseEntity = void 0;
const entity_decorator_js_1 = require("./decorators/entity.decorator.js");
const orm_const_js_1 = require("./orm.const.js");
class BaseEntity {
constructor(partial) {
const fields = entity_decorator_js_1.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[orm_const_js_1.REPOSITORY_KEY];
return !!(repo && repo.destroy(this));
}
async exists() {
const repo = this[orm_const_js_1.REPOSITORY_KEY];
return !!(repo && repo.exists(this));
}
toJSON() {
// this method is a placeholder and will be overwritten by declareEntity() method
return this;
}
}
exports.BaseEntity = BaseEntity;