UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

18 lines (17 loc) 880 B
import { EntityMetadata } from '../model/entity-metadata.js'; export function Index(arg0, arg1) { return function (target, propertyKey) { if (typeof target === 'function') { if (!(typeof arg0 === 'string' || Array.isArray(arg0))) throw new Error(`You must specify index column(s)`); const model = EntityMetadata.define(target); return EntityMetadata.addIndex(model, { ...arg1, columns: arg0 }); } 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 model = EntityMetadata.define(target.constructor); EntityMetadata.addIndex(model, { ...arg0, columns: [propertyKey] }); }; }