@joktec/mysql
Version:
JokTec - MySql Service
31 lines • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tables = void 0;
const core_1 = require("@joktec/core");
const typeorm_1 = require("typeorm");
const Tables = (options = {}) => {
return (target) => {
const className = target.name;
const decorators = [(0, core_1.SetMetadata)(className, options), (0, typeorm_1.Entity)(options)];
if (options.index?.length) {
decorators.push((0, typeorm_1.Index)(options.index, { background: true }));
}
if (options.unique?.length) {
decorators.push((0, typeorm_1.Index)(options.unique, { unique: true, background: true }));
}
if (options.textSearch?.length) {
decorators.push((0, typeorm_1.Index)(options.textSearch.map(String), { fulltext: true, background: true }));
}
if (options.customIndexes?.length) {
options.customIndexes.map((idxOpts) => {
if (idxOpts.name)
decorators.push((0, typeorm_1.Index)(idxOpts.name, idxOpts.fields, idxOpts));
else
decorators.push((0, typeorm_1.Index)(idxOpts.fields, idxOpts));
});
}
(0, core_1.applyDecorators)(...decorators)(target);
};
};
exports.Tables = Tables;
//# sourceMappingURL=table.decorator.js.map