valueQuery=`${tmpTable}INSERT${replacements.ignoreDuplicates} INTO ${quotedTable} (${replacements.attributes})${replacements.output} VALUES (${replacements.values})${replacements.onConflictDoNothing}${valueQuery}`;
valueQuery=`${tmpTable}INSERT${replacements.ignoreDuplicates} INTO ${quotedTable} (${replacements.attributes})${replacements.output} VALUES (${replacements.values})${replacements.onConflictDoNothing}${valueQuery}`;
emptyQuery=`${tmpTable}INSERT${replacements.ignoreDuplicates} INTO ${quotedTable}${replacements.output}${replacements.onConflictDoNothing}${emptyQuery}`;
emptyQuery=`${tmpTable}INSERT${replacements.ignoreDuplicates} INTO ${quotedTable}${replacements.output}${replacements.onConflictDoNothing}${emptyQuery}`;
constselectQuery=`SELECT (testfunc.response).${returningModelAttributes.join(', (testfunc.response).')}, testfunc.sequelize_caught_exception FROM pg_temp.testfunc();`;
options.exception='WHEN unique_violation THEN GET STACKED DIAGNOSTICS sequelize_caught_exception = PG_EXCEPTION_DETAIL;';
options.exception='WHEN unique_violation THEN GET STACKED DIAGNOSTICS sequelize_caught_exception = PG_EXCEPTION_DETAIL;';
valueQuery=`${`CREATE OR REPLACE FUNCTION pg_temp.testfunc(OUT response ${quotedTable}, OUT sequelize_caught_exception text) RETURNS RECORD AS ${delimiter}`+
valueQuery=`CREATE OR REPLACE FUNCTION pg_temp.testfunc(OUT response ${quotedTable}, OUT sequelize_caught_exception text) RETURNS RECORD AS ${delimiter
' BEGIN '}${valueQuery} INTO response; EXCEPTION ${options.exception} END ${delimiter
}BEGIN${valueQuery} RETURNING * INTO response; EXCEPTION ${options.exception} END ${delimiter} LANGUAGE plpgsql; ${selectQuery}${dropFunction}`;
constselectQuery=`SELECT ${returningModelAttributes.join(', ')} FROM pg_temp.testfunc();`;
options.exception='WHEN unique_violation THEN NULL;';
options.exception='WHEN unique_violation THEN NULL;';
valueQuery = `CREATEORREPLACEFUNCTIONpg_temp.testfunc()RETURNSSETOF${quotedTable} AS $body$ BEGIN RETURN QUERY ${valueQuery}; EXCEPTION ${options.exception} END; $body$ LANGUAGE plpgsql; SELECT * FROM pg_temp.testfunc(); DROP FUNCTION IF EXISTS pg_temp.testfunc();`;
valueQuery=`CREATE OR REPLACE FUNCTION pg_temp.testfunc() RETURNS SETOF ${quotedTable} AS $body$ BEGIN RETURN QUERY ${valueQuery
}RETURNING*;EXCEPTION${options.exception} END; $body$ LANGUAGE plpgsql; ${selectQuery}${dropFunction}`;
* Builds a new model instance and calls save on it.
* Builds a new model instance and calls save on it.
*
* @see
* @see
* {@link Model.build}
* {@link Model.build}
* @see
* @see
* {@link Model.save}
* {@link Model.save}
*
*
* @param {Object} values hash of data values to create new record with
* @param {Object} values Hash of data values to create new record with
* @param {Object} [options] build and query options
* @param {Object} [options] Build and query options
* @param {boolean} [options.raw=false] If set to true, values will ignore field and virtual setters.
* @param {boolean} [options.raw=false] If set to true, values will ignore field and virtual setters.
* @param {boolean} [options.isNewRecord=true] Is this new record
* @param {boolean} [options.isNewRecord=true] Is this new record
* @param {Array} [options.include] an array of include options - Used to build prefetched/included model instances. See `set`
* @param {Array} [options.include] An array of include options - Used to build prefetched/included model instances. See `set`
* @param {Array} [options.fields] If set, only columns matching those in fields will be saved
* @param {string[]} [options.fields] An optional array of strings, representing database columns. If fields is provided, only those columns will be validated and saved.
* @param {string[]} [options.fields] An optional array of strings, representing database columns. If fields is provided, only those columns will be validated and saved.
* @param {boolean} [options.silent=false] If true, the updatedAt timestamp will not be updated.
* @param {boolean} [options.silent=false] If true, the updatedAt timestamp will not be updated.
* @param {boolean} [options.validate=true] If false, validations won't be run.
* @param {boolean} [options.validate=true] If false, validations won't be run.
...
@@ -2207,7 +2206,7 @@ class Model {
...
@@ -2207,7 +2206,7 @@ class Model {
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {boolean} [options.returning=true] Return the affected rows (only for postgres)
* @param {boolean|Array} [options.returning=true] Appends RETURNING <model columns> to get back all defined values; if an array of column names, append RETURNING <columns> to get back specific columns (Postgres only)
* @param {boolean} [options.validate=true] Run validations before the row is inserted
* @param {boolean} [options.validate=true] Run validations before the row is inserted
* @param {Array} [options.fields=Object.keys(this.attributes)] The fields to insert / update. Defaults to all changed fields
* @param {Array} [options.fields=Object.keys(this.attributes)] The fields to insert / update. Defaults to all changed fields
* @param {boolean} [options.hooks=true] Run before / after upsert hooks?
* @param {boolean} [options.hooks=true] Run before / after upsert hooks?
* @param {boolean} [options.returning=false] Append RETURNING * to get back auto generated values (Postgres only)
* @param {boolean} [options.returning=false] If true, fetches back auto generated values (Postgres only)
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
*
*
* @returns {Promise<boolean>} Returns a boolean indicating whether the row was created or updated. For MySQL/MariaDB, it returns `true` when inserted and `false` when updated. For Postgres/MSSQL with (options.returning=true), it returns record and created boolean with signature `<Model, created>`.
* @returns {Promise<boolean>} Returns a boolean indicating whether the row was created or updated. For MySQL/MariaDB, it returns `true` when inserted and `false` when updated. For Postgres/MSSQL with `options.returning` true, it returns record and created boolean with signature `<Model, created>`.
*/
*/
staticupsert(values,options){
staticupsert(values,options){
options=Object.assign({
options=Object.assign({
...
@@ -2524,7 +2524,7 @@ class Model {
...
@@ -2524,7 +2524,7 @@ class Model {
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {boolean|Array} [options.returning=false] If true, append RETURNING * to get back all values; if an array of column names, append RETURNING <columns> to get back specific columns (Postgres only)
* @param {boolean|Array} [options.returning=false] If true, append RETURNING <model columns> to get back all defined values; if an array of column names, append RETURNING <columns> to get back specific columns (Postgres only)
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {boolean} [options.hooks=true] Run before / after bulk update hooks?
* @param {boolean} [options.hooks=true] Run before / after bulk update hooks?
* @param {boolean} [options.sideEffects=true] Whether or not to update the side effects of any virtual setters.
* @param {boolean} [options.sideEffects=true] Whether or not to update the side effects of any virtual setters.
* @param {boolean} [options.individualHooks=false] Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs. A select is needed, because the row data needs to be passed to the hooks
* @param {boolean} [options.individualHooks=false] Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs. A select is needed, because the row data needs to be passed to the hooks
* @param {boolean} [options.returning=false] Return the affected rows (only for postgres)
* @param {boolean|Array} [options.returning=false] If true, append RETURNING <model columns> to get back all defined values; if an array of column names, append RETURNING <columns> to get back specific columns (Postgres only)
* @param {number} [options.limit] How many rows to update (only for mysql and mariadb, implemented as TOP(n) for MSSQL; for sqlite it is supported only when rowid is present)
* @param {number} [options.limit] How many rows to update (only for mysql and mariadb, implemented as TOP(n) for MSSQL; for sqlite it is supported only when rowid is present)
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
...
@@ -3042,7 +3042,7 @@ class Model {
...
@@ -3042,7 +3042,7 @@ class Model {
* @param {boolean} [options.silent=false] If true, the updatedAt timestamp will not be updated.
* @param {boolean} [options.silent=false] If true, the updatedAt timestamp will not be updated.
*
*
* @returns {Promise<Array<number,number>>} The promise returns an array with one or two elements. The first element is always the number
* @returns {Promise<Array<number,number>>} The promise returns an array with one or two elements. The first element is always the number
* of affected rows, while the second element is the actual affected rows (only supported in postgres with `options.returning` true.)
* of affected rows, while the second element is the actual affected rows (only supported in postgres with `options.returning` true).
*
*
*/
*/
staticupdate(values,options){
staticupdate(values,options){
...
@@ -3325,7 +3325,7 @@ class Model {
...
@@ -3325,7 +3325,7 @@ class Model {
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
*
*
* @returns {Promise<Model[],?number>} returns an array of affected rows and affected count with `options.returning: true`, whenever supported by dialect
* @returns {Promise<Model[],?number>} returns an array of affected rows and affected count with `options.returning` true, whenever supported by dialect
*/
*/
staticincrement(fields,options){
staticincrement(fields,options){
options=options||{};
options=options||{};
...
@@ -3411,8 +3411,8 @@ class Model {
...
@@ -3411,8 +3411,8 @@ class Model {
* @see
* @see
* {@link Model#reload}
* {@link Model#reload}
* @since 4.36.0
* @since 4.36.0
*
* @returns {Promise<Model[],?number>} returns an array of affected rows and affected count with `options.returning: true`, whenever supported by dialect
* @returns {Promise<Model[],?number>} returns an array of affected rows and affected count with `options.returning` true, whenever supported by dialect