@sequelize/sqlite3
Advanced tools
Comparing version 7.0.0-alpha.42 to 7.0.0-alpha.43
@@ -57,2 +57,3 @@ "use strict"; | ||
"RIGHT JOIN": false, | ||
returnValues: "returning", | ||
inserts: { | ||
@@ -59,0 +60,0 @@ ignoreDuplicates: " OR IGNORE", |
@@ -116,2 +116,8 @@ "use strict"; | ||
const bindParam = options.bindParam === void 0 ? this.bindParam(bind) : options.bindParam; | ||
let suffix = ""; | ||
if (options.returning) { | ||
const returnValues = this.generateReturnValues(attributes, options); | ||
suffix += returnValues.returningFragment; | ||
options.mapToModel = true; | ||
} | ||
if (attributes) { | ||
@@ -138,5 +144,5 @@ (0, import_each.default)(attributes, (attribute, key) => { | ||
if (options.limit) { | ||
query = `UPDATE ${this.quoteTable(tableName)} SET ${values.join(",")} WHERE rowid IN (SELECT rowid FROM ${this.quoteTable(tableName)} ${this.whereQuery(where, whereOptions)} LIMIT ${this.escape(options.limit, void 0, options)})`.trim(); | ||
query = `UPDATE ${this.quoteTable(tableName)} SET ${values.join(",")} WHERE rowid IN (SELECT rowid FROM ${this.quoteTable(tableName)} ${this.whereQuery(where, whereOptions)} LIMIT ${this.escape(options.limit, void 0, options)})${suffix}`.trim(); | ||
} else { | ||
query = `UPDATE ${this.quoteTable(tableName)} SET ${values.join(",")} ${this.whereQuery(where, whereOptions)}`.trim(); | ||
query = `UPDATE ${this.quoteTable(tableName)} SET ${values.join(",")} ${this.whereQuery(where, whereOptions)}${suffix}`.trim(); | ||
} | ||
@@ -143,0 +149,0 @@ const result = { query }; |
@@ -69,20 +69,38 @@ "use strict"; | ||
_handleQueryResponse(metaData, results) { | ||
let result = this.instance; | ||
if (this.isInsertQuery(results, metaData) || this.isUpsertQuery()) { | ||
this.handleInsertQuery(results, metaData); | ||
if (!this.instance) { | ||
const modelDefinition = this.model?.modelDefinition; | ||
if (metaData.constructor.name === "Statement" && modelDefinition?.autoIncrementAttributeName && modelDefinition?.autoIncrementAttributeName === this.model.primaryKeyAttribute) { | ||
const startId = metaData[this.getInsertIdField()] - metaData.changes + 1; | ||
result = []; | ||
for (let i = startId; i < startId + metaData.changes; i++) { | ||
result.push({ [modelDefinition.getColumnName(this.model.primaryKeyAttribute)]: i }); | ||
if (this.isInsertQuery() || this.isUpdateQuery() || this.isUpsertQuery()) { | ||
if (this.instance && this.instance.dataValues) { | ||
if (this.isInsertQuery() && !this.isUpsertQuery() && results.length === 0) { | ||
throw new import_core.EmptyResultError(); | ||
} | ||
if (Array.isArray(results) && results[0]) { | ||
for (const attributeOrColumnName of Object.keys(results[0])) { | ||
const modelDefinition = this.model.modelDefinition; | ||
const attribute = modelDefinition.columns.get(attributeOrColumnName); | ||
const updatedValue = this._parseDatabaseValue( | ||
results[0][attributeOrColumnName], | ||
attribute?.type | ||
); | ||
this.instance.set(attribute?.attributeName ?? attributeOrColumnName, updatedValue, { | ||
raw: true, | ||
comesFromDatabase: true | ||
}); | ||
} | ||
} else { | ||
result = metaData[this.getInsertIdField()]; | ||
} | ||
} | ||
if (this.isUpsertQuery()) { | ||
return [this.instance, null]; | ||
} | ||
return [ | ||
this.instance || results && (this.options.plain && results[0] || results) || void 0, | ||
this.options.returning ? results.length : metaData.changes | ||
]; | ||
} | ||
if (this.isBulkUpdateQuery()) { | ||
return this.options.returning ? this.handleSelectQuery(results) : metaData.changes; | ||
} | ||
if (this.isDeleteQuery()) { | ||
return metaData.changes; | ||
} | ||
if (this.isShowConstraintsQuery()) { | ||
return result; | ||
return results; | ||
} | ||
@@ -102,3 +120,3 @@ if (this.isSelectQuery()) { | ||
if (this.sql.includes("PRAGMA TABLE_INFO")) { | ||
result = {}; | ||
const result = {}; | ||
let defaultValue; | ||
@@ -128,15 +146,6 @@ for (const _result of results) { | ||
} | ||
if ([import_core.QueryTypes.BULKUPDATE, import_core.QueryTypes.DELETE].includes(this.options.type)) { | ||
return metaData.changes; | ||
} | ||
if (this.options.type === import_core.QueryTypes.RAW) { | ||
if (this.isRawQuery()) { | ||
return [results, metaData]; | ||
} | ||
if (this.isUpsertQuery()) { | ||
return [result, null]; | ||
} | ||
if (this.isUpdateQuery() || this.isInsertQuery()) { | ||
return [result, metaData.changes]; | ||
} | ||
return result; | ||
return this.instance; | ||
} | ||
@@ -148,3 +157,2 @@ async run(sql, parameters) { | ||
const complete = this._logQuery(sql, debug, parameters); | ||
const columnTypes = {}; | ||
const executeSql = async () => { | ||
@@ -177,26 +185,2 @@ if (!parameters) { | ||
}; | ||
if (method === "all") { | ||
let tableNames = []; | ||
if (this.options && this.options.tableNames) { | ||
tableNames = this.options.tableNames; | ||
} else if (/from `(.*?)`/i.test(this.sql)) { | ||
tableNames.push(/from `(.*?)`/i.exec(this.sql)[1]); | ||
} | ||
tableNames = tableNames.filter( | ||
(tableName) => !(tableName in columnTypes) && tableName !== "sqlite_master" | ||
); | ||
if (tableNames.length === 0) { | ||
return executeSql(); | ||
} | ||
await Promise.all( | ||
tableNames.map(async (tableName) => { | ||
tableName = tableName.replaceAll("`", ""); | ||
columnTypes[tableName] = {}; | ||
const { results } = await this.#allSeries(conn, `PRAGMA table_info(\`${tableName}\`)`); | ||
for (const result of results) { | ||
columnTypes[tableName][result.name] = result.type; | ||
} | ||
}) | ||
); | ||
} | ||
return executeSql(); | ||
@@ -303,3 +287,6 @@ } | ||
getDatabaseMethod() { | ||
if (this.isInsertQuery() || this.isUpdateQuery() || this.isUpsertQuery() || this.isBulkUpdateQuery() || this.sql.toLowerCase().includes("CREATE TEMPORARY TABLE".toLowerCase()) || this.isDeleteQuery()) { | ||
if (this.isBulkUpdateQuery() || this.isInsertQuery() || this.isUpdateQuery() || this.isUpsertQuery()) { | ||
return this.options.returning ? "all" : "run"; | ||
} | ||
if (this.isDeleteQuery() || this.sql.toLowerCase().includes("CREATE TEMPORARY TABLE".toLowerCase())) { | ||
return "run"; | ||
@@ -306,0 +293,0 @@ } |
@@ -34,3 +34,3 @@ { | ||
"type": "commonjs", | ||
"version": "7.0.0-alpha.42", | ||
"version": "7.0.0-alpha.43", | ||
"publishConfig": { | ||
@@ -40,8 +40,8 @@ "access": "public" | ||
"dependencies": { | ||
"@sequelize/core": "7.0.0-alpha.42", | ||
"@sequelize/utils": "7.0.0-alpha.42", | ||
"@sequelize/core": "7.0.0-alpha.43", | ||
"@sequelize/utils": "7.0.0-alpha.43", | ||
"lodash": "^4.17.21", | ||
"sqlite3": "^5.1.7" | ||
}, | ||
"gitHead": "4fd3f5c33e3dc1faecb8841d840a3ea2c327fc84" | ||
"gitHead": "1f38ae7e01e36d2497eb22eec78ea58e7bec7e31" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
203291
2203
+ Added@sequelize/core@7.0.0-alpha.43(transitive)
+ Added@sequelize/utils@7.0.0-alpha.43(transitive)
- Removed@sequelize/core@7.0.0-alpha.42(transitive)
- Removed@sequelize/utils@7.0.0-alpha.42(transitive)