@sqb/connect
Version:
Multi-dialect database connection framework written with TypeScript
33 lines (32 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Column = Column;
const builder_1 = require("@sqb/builder");
const entity_metadata_js_1 = require("../model/entity-metadata.js");
const orm_const_js_1 = require("../orm.const.js");
function Column(arg0) {
return Column[orm_const_js_1.DECORATOR_FACTORY](arg0);
}
Column[orm_const_js_1.DECORATOR_FACTORY] = function (arg0) {
return (target, propertyKey) => {
if (typeof propertyKey !== 'string')
throw new Error('Symbol properties are not accepted');
const options = (typeof arg0 === 'string' ? { dataType: arg0 } : arg0) || {};
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
if (!options.type) {
const typ = Reflect.getMetadata('design:type', entity.ctor.prototype, propertyKey);
if (typ === Array) {
options.type = String;
options.isArray = true;
}
else
options.type = typ;
}
if (!options.dataType &&
typeof options.type === 'function' &&
entity_metadata_js_1.EntityMetadata.get(options.type)) {
options.dataType = builder_1.DataType.JSON;
}
entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey, options);
};
};