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 <%= table %>, 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+
' LANGUAGE plpgsql; SELECT (testfunc.response).*, testfunc.sequelize_caught_exception FROM pg_temp.testfunc(); DROP FUNCTION IF EXISTS pg_temp.testfunc()';
}else{
options.exception='WHEN unique_violation THEN NULL;';
valueQuery='CREATE OR REPLACE FUNCTION pg_temp.testfunc() RETURNS SETOF <%= table %> 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}; EXCEPTION ${options.exception} END; $body$ LANGUAGE plpgsql; SELECT * FROM pg_temp.testfunc(); DROP FUNCTION IF EXISTS pg_temp.testfunc();`;
constquery=`${tmpTable}UPDATE ${this.quoteTable(tableName)} SET ${values.join(',')}${outputFragment}${this.whereQuery(where,whereOptions)}${suffix}`.trim();
// Used by Postgres upsertQuery and calls to here with options.exception set to true
return`CREATE TABLE IF NOT EXISTS ${table} (${attributesClause}) ENGINE=${engine}${comment}${charset}${collation}${initialAutoIncrement}${rowFormat};`;
}
...
...
@@ -167,7 +154,7 @@ class MySQLQueryGenerator extends AbstractQueryGenerator {
* @param {string} path The path to the file that holds the model you want to import. If the part is relative, it will be resolved relatively to the calling file
* @param {string} importPath The path to the file that holds the model you want to import. If the part is relative, it will be resolved relatively to the calling file
*
* @returns {Model} Imported model, returned from cache if was already imported
mssql:'declare @tmp table ([id] INTEGER,[user_name] NVARCHAR(255));UPDATE [users] SET [user_name]=$1 OUTPUT INSERTED.[id],INSERTED.[user_name] into @tmp WHERE [id] = $2;select * from @tmp',
mssql:'declare @tmp table ([id] INTEGER,[user_name] NVARCHAR(255));UPDATE [users] SET [user_name]=$1 OUTPUT INSERTED.[id],INSERTED.[user_name] into @tmp WHERE [id] = $2;select * from @tmp',
postgres:'UPDATE "users" SET "user_name"=$1 WHERE "id" = $2 RETURNING *',
default:'UPDATE `users` SET `user_name`=$1 WHERE `id` = $2'