8 lines
22 KiB
Plaintext
8 lines
22 KiB
Plaintext
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../../src/dialects/sqlite/query.js"],
|
||
|
"sourcesContent": ["'use strict';\n\nconst _ = require('lodash');\nconst Utils = require('../../utils');\nconst AbstractQuery = require('../abstract/query');\nconst QueryTypes = require('../../query-types');\nconst sequelizeErrors = require('../../errors');\nconst parserStore = require('../parserStore')('sqlite');\nconst { logger } = require('../../utils/logger');\n\nconst debug = logger.debugContext('sql:sqlite');\n\n\nclass Query extends AbstractQuery {\n getInsertIdField() {\n return 'lastID';\n }\n\n /**\n * rewrite query with parameters.\n *\n * @param {string} sql\n * @param {Array|object} values\n * @param {string} dialect\n * @private\n */\n static formatBindParameters(sql, values, dialect) {\n let bindParam;\n if (Array.isArray(values)) {\n bindParam = {};\n values.forEach((v, i) => {\n bindParam[`$${i + 1}`] = v;\n });\n sql = AbstractQuery.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0];\n } else {\n bindParam = {};\n if (typeof values === 'object') {\n for (const k of Object.keys(values)) {\n bindParam[`$${k}`] = values[k];\n }\n }\n sql = AbstractQuery.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0];\n }\n return [sql, bindParam];\n }\n\n _collectModels(include, prefix) {\n const ret = {};\n\n if (include) {\n for (const _include of include) {\n let key;\n if (!prefix) {\n key = _include.as;\n } else {\n key = `${prefix}.${_include.as}`;\n }\n ret[key] = _include.model;\n\n if (_include.include) {\n _.merge(ret, this._collectModels(_include.include, key));\n }\n }\n }\n\n return ret;\n }\n\n _handleQueryResponse(metaData, columnTypes, err, results, errStack) {\n if (err) {\n err.sql = this.sql;\n throw this.formatError(err, errStack);\n }\n let result = this.instance;\n\n // add the inserted row id to the instance\n if (this.isInsertQuery(results, metaData) || this.isUpsertQuery()) {\n this.handleInsertQuery(results, metaData);\n if (!this.instance) {\n // handle bulkCreate AI primary key\n if (\n metaData.constructor.name === 'Statement'\n && this.model\n && this.model.autoIncrementAttribute\n && this.model.autoIncrementAttribute === this.model.primaryKeyAttribute\n && this.model.rawAttributes[this.model.primaryKeyAttribute]\n ) {\n const startId = metaData[this.getInsertIdField()] - metaData.changes + 1;\n result = [];\n for (let i = startId; i < startId + metaData.changes; i++) {\n result.push({ [this.model.rawAttributes[this.model.primaryKeyAttribute].field]: i });\n }\n } else {\n result = metaData[this.getInsertIdField()];\n }\n }\n }\n\n if (this.isShowTablesQuery()) {\n return results.map(row => row.name);\n }\n if (this.isShowConstraintsQuery()) {\n result = results;\n if (results && results[0] && results[0].sql) {\n result = this.parseConstraintsFromSql(results[0].sql);\n }\n return result;\n }\n if (this.isSelectQuery()) {\n if (this.options.raw) {\n return this.handleSelectQuery(results);\n }\n // This is a map of prefix strings to models, e.g. user.projects -> Project model\n const prefixes = this._collectModels(this.options.include);\n\n results = results.map(result => {\n return _.mapValues(result, (value, name) => {\n let model;\n if (name.includes('.')) {\n const lastind = name.lastIndexOf('.');\n\n model = prefixes[name.substr(0, lastind)];\n\n name = name.substr(lastind + 1);\n } else {\n model = this.options.model;\n }\n\n const tableName = model.getTableName().toString().replace(/`/g, '');\n const tableTypes = columnTypes[tableName] || {};\n\n if (tableTypes && !(n
|
||
|
"mappings": ";AAEA,MAAM,IAAI,QAAQ;AAClB,MAAM,QAAQ,QAAQ;AACtB,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;AAC3B,MAAM,kBAAkB,QAAQ;AAChC,MAAM,cAAc,QAAQ,kBAAkB;AAC9C,MAAM,EAAE,WAAW,QAAQ;AAE3B,MAAM,QAAQ,OAAO,aAAa;AAGlC,oBAAoB,cAAc;AAAA,EAChC,mBAAmB;AACjB,WAAO;AAAA;AAAA,SAWF,qBAAqB,KAAK,QAAQ,SAAS;AAChD,QAAI;AACJ,QAAI,MAAM,QAAQ,SAAS;AACzB,kBAAY;AACZ,aAAO,QAAQ,CAAC,GAAG,MAAM;AACvB,kBAAU,IAAI,IAAI,OAAO;AAAA;AAE3B,YAAM,cAAc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