@sqb/connect
Version:
Multi-dialect database connection framework written with TypeScript
25 lines (24 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrimaryKey = PrimaryKey;
const entity_metadata_js_1 = require("../model/entity-metadata.js");
const column_decorator_js_1 = require("./column.decorator.js");
function PrimaryKey(arg0, arg1) {
return function (target, propertyKey) {
if (arguments.length === 1) {
if (!(typeof arg0 === 'string' || Array.isArray(arg0))) {
throw new Error(`You must specify primary index column(s)`);
}
const meta = entity_metadata_js_1.EntityMetadata.define(target);
entity_metadata_js_1.EntityMetadata.setPrimaryKeys(meta, arg0, arg1);
return;
}
if (!target.constructor)
throw new Error('Property decorators can be used for class properties only');
if (typeof propertyKey !== 'string')
throw new Error('Index() decorator can be used for string property keys only');
const meta = entity_metadata_js_1.EntityMetadata.define(target.constructor);
(0, column_decorator_js_1.Column)({ notNull: true })(target, propertyKey);
entity_metadata_js_1.EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
};
}