API/api.medcify.app/node_modules/sequelize/lib/dialects/postgres/query-interface.js.map

8 lines
12 KiB
Plaintext
Raw Normal View History

2022-09-26 06:11:44 +00:00
{
"version": 3,
"sources": ["../../../src/dialects/postgres/query-interface.js"],
"sourcesContent": ["'use strict';\n\nconst DataTypes = require('../../data-types');\nconst QueryTypes = require('../../query-types');\nconst { QueryInterface } = require('../abstract/query-interface');\nconst Utils = require('../../utils');\nconst Deferrable = require('../../deferrable');\n\n/**\n * The interface that Sequelize uses to talk with Postgres database\n */\nclass PostgresQueryInterface extends QueryInterface {\n /**\n * Ensure enum and their values.\n *\n * @param {string} tableName Name of table to create\n * @param {object} attributes Object representing a list of normalized table attributes\n * @param {object} [options]\n * @param {Model} [model]\n *\n * @protected\n */\n async ensureEnums(tableName, attributes, options, model) {\n const keys = Object.keys(attributes);\n const keyLen = keys.length;\n\n let sql = '';\n let promises = [];\n let i = 0;\n\n for (i = 0; i < keyLen; i++) {\n const attribute = attributes[keys[i]];\n const type = attribute.type;\n\n if (\n type instanceof DataTypes.ENUM ||\n type instanceof DataTypes.ARRAY && type.type instanceof DataTypes.ENUM //ARRAY sub type is ENUM\n ) {\n sql = this.queryGenerator.pgListEnums(tableName, attribute.field || keys[i], options);\n promises.push(this.sequelize.query(\n sql,\n { ...options, plain: true, raw: true, type: QueryTypes.SELECT }\n ));\n }\n }\n\n const results = await Promise.all(promises);\n promises = [];\n let enumIdx = 0;\n\n // This little function allows us to re-use the same code that prepends or appends new value to enum array\n const addEnumValue = (field, value, relativeValue, position = 'before', spliceStart = promises.length) => {\n const valueOptions = { ...options };\n valueOptions.before = null;\n valueOptions.after = null;\n\n switch (position) {\n case 'after':\n valueOptions.after = relativeValue;\n break;\n case 'before':\n default:\n valueOptions.before = relativeValue;\n break;\n }\n\n promises.splice(spliceStart, 0, () => {\n return this.sequelize.query(this.queryGenerator.pgEnumAdd(\n tableName, field, value, valueOptions\n ), valueOptions);\n });\n };\n\n for (i = 0; i < keyLen; i++) {\n const attribute = attributes[keys[i]];\n const type = attribute.type;\n const enumType = type.type || type;\n const field = attribute.field || keys[i];\n\n if (\n type instanceof DataTypes.ENUM ||\n type instanceof DataTypes.ARRAY && enumType instanceof DataTypes.ENUM //ARRAY sub type is ENUM\n ) {\n // If the enum type doesn't exist then create it\n if (!results[enumIdx]) {\n promises.push(() => {\n return this.sequelize.query(this.queryGenerator.pgEnum(tableName, field, enumType, options), { ...options, raw: true });\n });\n } else if (!!results[enumIdx] && !!model) {\n const enumVals = this.queryGenerator.fromArray(results[enumIdx].enum_value);\n const vals = enumType.values;\n\n // Going through already existing values allows us to make queries that depend on those values\n // We will prepend all new values between the old ones, but keep in mind - we can't change order of already existing values\n // Then we append the rest of new values AFTER the latest already existing value\n // E.g.: [1,2] -> [0,2,1] ==> [1,0,2]\n // E.g.: [1,2,3] -> [2,1,3,4] ==> [1,2,3,4]\n // E.g.: [1] -> [0,2,3] ==> [1,0,2,3]\n let lastOldEnumValue;\n let rightestPosition = -1;\n for (let oldIndex = 0; oldIndex < enumVals.length; oldIndex++) {\n const enumVal = enumVals[oldIndex];\n const newIdx = vals.indexOf(enumVal);\n lastOldEnumValue = enumVal;\n\n if (newIdx === -1) {\n continue;\n }\n\n const newValuesBefore = vals.slice(0,
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,YAAY,QAAQ;AAC1B,MAAM,aAAa,QAAQ;AAC3B,MAAM,EAAE,mBAAmB,QAAQ;AACnC,MAAM,QAAQ,QAAQ;AACtB,MAAM,aAAa,QAAQ;AAK3B,qCAAqC,eAAe;AAAA,QAW5C,YAAY,WAAW,YAAY,SAAS,OAAO;AACvD,UAAM,OAAO,OAAO,KAAK;AACzB,UAAM,SAAS,KAAK;AAEpB,QAAI,MAAM;AACV,QAAI,WAAW;AACf,QAAI,IAAI;AAER,SAAK,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC3B,YAAM,YAAY,WAAW,KAAK;AAClC,YAAM,OAAO,UAAU;AAEvB,UAC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