UNPKG

1.77 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var __1 = require("../");
4/**
5 * Creates a database index.
6 * Can be used on entity property or on entity.
7 * Can create indices with composite columns when used on entity.
8 */
9function Index(nameOrFieldsOrOptions, maybeFieldsOrOptions, maybeOptions) {
10 // normalize parameters
11 var name = typeof nameOrFieldsOrOptions === "string" ? nameOrFieldsOrOptions : undefined;
12 var fields = typeof nameOrFieldsOrOptions === "string" ? maybeFieldsOrOptions : nameOrFieldsOrOptions;
13 var options = (typeof nameOrFieldsOrOptions === "object" && !Array.isArray(nameOrFieldsOrOptions)) ? nameOrFieldsOrOptions : maybeOptions;
14 if (!options)
15 options = (typeof maybeFieldsOrOptions === "object" && !Array.isArray(maybeFieldsOrOptions)) ? maybeFieldsOrOptions : maybeOptions;
16 return function (clsOrObject, propertyName) {
17 __1.getMetadataArgsStorage().indices.push({
18 target: propertyName ? clsOrObject.constructor : clsOrObject,
19 name: name,
20 columns: propertyName ? [propertyName] : fields,
21 synchronize: options && options.synchronize === false ? false : true,
22 where: options ? options.where : undefined,
23 unique: options && options.unique ? true : false,
24 spatial: options && options.spatial ? true : false,
25 fulltext: options && options.fulltext ? true : false,
26 sparse: options && options.sparse ? true : false,
27 background: options && options.background ? true : false,
28 expireAfterSeconds: options && options.expireAfterSeconds ? options.expireAfterSeconds : undefined
29 });
30 };
31}
32exports.Index = Index;
33
34//# sourceMappingURL=Index.js.map