UNPKG

1.62 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Column = void 0;
4const attribute_service_1 = require("./attribute-service");
5const data_type_service_1 = require("../../sequelize/data-type/data-type-service");
6const model_service_1 = require("../shared/model-service");
7function Column(...args) {
8 // In case of no specified options, we infer the
9 // sequelize data type by the type of the property
10 if (args.length >= 2) {
11 const target = args[0];
12 const propertyName = args[1];
13 const propertyDescriptor = args[2];
14 annotate(target, propertyName, propertyDescriptor);
15 return;
16 }
17 return (target, propertyName, propertyDescriptor) => {
18 annotate(target, propertyName, propertyDescriptor, args[0]);
19 };
20}
21exports.Column = Column;
22function annotate(target, propertyName, propertyDescriptor, optionsOrDataType = {}) {
23 let options;
24 if ((0, data_type_service_1.isDataType)(optionsOrDataType)) {
25 options = {
26 type: optionsOrDataType,
27 };
28 }
29 else {
30 options = Object.assign({}, optionsOrDataType);
31 if (!options.type) {
32 options.type = (0, model_service_1.getSequelizeTypeByDesignType)(target, propertyName);
33 }
34 }
35 if (propertyDescriptor) {
36 if (propertyDescriptor.get) {
37 options.get = propertyDescriptor.get;
38 }
39 if (propertyDescriptor.set) {
40 options.set = propertyDescriptor.set;
41 }
42 }
43 (0, attribute_service_1.addAttribute)(target, propertyName, options);
44}
45//# sourceMappingURL=column.js.map
\No newline at end of file