@sqb/connect
Version:
Multi-dialect database connection framework written with TypeScript
22 lines (21 loc) • 994 B
JavaScript
import { EntityMetadata } from '../model/entity-metadata.js';
import { Column } from './column.decorator.js';
export 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 = EntityMetadata.define(target);
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 = EntityMetadata.define(target.constructor);
Column({ notNull: true })(target, propertyKey);
EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
};
}