You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8 lines
6.5 KiB

{
"version": 3,
"sources": ["../../../src/dialects/db2/query-interface.js"],
"sourcesContent": ["'use strict';\n\nconst _ = require('lodash');\nconst Utils = require('../../utils');\nconst Op = require('../../operators');\nconst { QueryInterface } = require('../abstract/query-interface');\nconst QueryTypes = require('../../query-types');\n\n/**\n * The interface that Sequelize uses to talk with Db2 database\n */\nclass Db2QueryInterface extends QueryInterface {\n async getForeignKeyReferencesForTable(tableName, options) {\n const queryOptions = {\n ...options,\n type: QueryTypes.FOREIGNKEYS\n };\n const query = this.queryGenerator.getForeignKeysQuery(tableName, this.sequelize.config.username.toUpperCase());\n return this.sequelize.query(query, queryOptions);\n }\n\n async upsert(tableName, insertValues, updateValues, where, options) {\n options = { ...options };\n\n const model = options.model;\n const wheres = [];\n const attributes = Object.keys(insertValues);\n let indexes = [];\n let indexFields;\n\n options = _.clone(options);\n\n if (!Utils.isWhereEmpty(where)) {\n wheres.push(where);\n }\n\n // Lets combine unique keys and indexes into one\n indexes = _.map(model.uniqueKeys, value => {\n return value.fields;\n });\n\n model._indexes.forEach(value => {\n if (value.unique) {\n // fields in the index may both the strings or objects with an attribute property - lets sanitize that\n indexFields = value.fields.map(field => {\n if (_.isPlainObject(field)) {\n return field.attribute;\n }\n return field;\n });\n indexes.push(indexFields);\n }\n });\n\n for (const index of indexes) {\n if (_.intersection(attributes, index).length === index.length) {\n where = {};\n for (const field of index) {\n where[field] = insertValues[field];\n }\n wheres.push(where);\n }\n }\n\n where = { [Op.or]: wheres };\n\n options.type = QueryTypes.UPSERT;\n options.raw = true;\n\n const sql = this.queryGenerator.upsertQuery(tableName, insertValues, updateValues, where, model, options);\n const result = await this.sequelize.query(sql, options);\n return [result, undefined];\n }\n\n async createTable(tableName, attributes, options, model) {\n let sql = '';\n\n options = { ...options };\n\n if (options && options.uniqueKeys) {\n _.forOwn(options.uniqueKeys, uniqueKey => {\n if (uniqueKey.customIndex === undefined) {\n uniqueKey.customIndex = true;\n }\n });\n }\n\n if (model) {\n options.uniqueKeys = options.uniqueKeys || model.uniqueKeys;\n }\n attributes = _.mapValues(\n attributes,\n attribute => this.sequelize.normalizeAttribute(attribute)\n ); \n if (options.indexes) {\n options.indexes.forEach(fields=>{\n const fieldArr = fields.fields;\n if (fieldArr.length === 1) {\n fieldArr.forEach(field=>{ \n for (const property in attributes) {\n if (field === attributes[property].field) {\n attributes[property].unique = true;\n }\n }\n });\n }\n });\n }\n if (options.alter) {\n if (options.indexes) {\n options.indexes.forEach(fields=>{\n const fieldArr = fields.fields;\n if (fieldArr.length === 1) {\n fieldArr.forEach(field=>{ \n for (const property in attributes) {\n if (field === attributes[property].field && attributes[property].unique) {\n attributes[property].unique = false;\n }\n }\n });\n }\n });\n }\n }\n\n if (\n !tableName.schema &&\n (options.schema || !!model && model._schema)\n ) {\n tableName = this.queryGenerator.addSchema({\n tableName,\n _schema: !!model && model._schema || options.schema\n });\n }\n\n attributes = this.queryGenerator.attributesToSQL(attributes, { table: tableName, context: 'c
"mappings": ";;;;;;;;;;;;;;;;;;;;AAEA,MAAM,IAAI,QAAQ;AAClB,MAAM,QAAQ,QAAQ;AACtB,MAAM,KAAK,QAAQ;AACnB,MAAM,EAAE,mBAAmB,QAAQ;AACnC,MAAM,aAAa,QAAQ;AAK3B,gCAAgC,eAAe;AAAA,QACvC,gCAAgC,WAAW,SAAS;AACxD,UAAM,eAAe,iCAChB,UADgB;AAAA,MAEnB,MAAM,WAAW;AAAA;AAEnB,UAAM,QAAQ,KAAK,eAAe,oBAAoB,WAAW,KAAK,UAAU,OAAO,SAAS;AAChG,WAAO,KAAK,UAAU,MAAM,OAAO;AAAA;AAAA,QAG/B,OAAO,WAAW,cAAc,cAAc,OAAO,SAAS;AAClE,cAAU,mBAAK;AAEf,UAAM,QAAQ,QAAQ;AACtB,UAAM,SAAS;AACf,UAAM,aAAa,OAAO,KAAK;AAC/B,QAAI,UAAU;AACd,QAAI;AAEJ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