不要怂,就是干,撸起袖子干!

Commit 7275c7c6 by Felix Becker Committed by Jan Aagaard Meier

ES6 refactor: dialects / MSSQL (#6049)

* ES6 refactor of MSSQL ConnectionManager

classes, let, const, arrow functions, export default

* Make Mssql Query an ES6 class

* ES6 refactor of Mssql Query

let, const, arrow functions, property shorthands, for of, export default
1 parent 3ff27d10
'use strict'; 'use strict';
var AbstractConnectionManager = require('../abstract/connection-manager') const AbstractConnectionManager = require('../abstract/connection-manager');
, ConnectionManager const ResourceLock = require('./resource-lock');
, ResourceLock = require('./resource-lock') const Promise = require('../../promise');
, Utils = require('../../utils') const sequelizeErrors = require('../../errors');
, Promise = require('../../promise') const parserStore = require('../parserStore')('mssql');
, sequelizeErrors = require('../../errors') const _ = require('lodash');
, parserStore = require('../parserStore')('mssql')
, _ = require('lodash'); class ConnectionManager extends AbstractConnectionManager {
constructor(dialect, sequelize) {
ConnectionManager = function(dialect, sequelize) { super(dialect, sequelize);
AbstractConnectionManager.call(this, dialect, sequelize);
this.sequelize = sequelize;
this.sequelize = sequelize; this.sequelize.config.port = this.sequelize.config.port || 1433;
this.sequelize.config.port = this.sequelize.config.port || 1433; try {
try { this.lib = require(sequelize.config.dialectModulePath || 'tedious');
this.lib = require(sequelize.config.dialectModulePath || 'tedious'); } catch (err) {
} catch (err) { if (err.code === 'MODULE_NOT_FOUND') {
if (err.code === 'MODULE_NOT_FOUND') { throw new Error('Please install tedious package manually');
throw new Error('Please install tedious package manually'); }
throw err;
} }
throw err;
} }
};
Utils._.extend(ConnectionManager.prototype, AbstractConnectionManager.prototype);
// Expose this as a method so that the parsing may be updated when the user has added additional, custom types
ConnectionManager.prototype.$refreshTypeParser = function (dataType) {
parserStore.refresh(dataType);
};
ConnectionManager.prototype.$clearTypeParser = function () {
parserStore.clear();
};
ConnectionManager.prototype.connect = function(config) {
var self = this;
return new Promise(function (resolve, reject) {
var connectionConfig = {
userName: config.username,
password: config.password,
server: config.host,
options: {
port: config.port,
database: config.database
}
};
if (config.dialectOptions) { // Expose this as a method so that the parsing may be updated when the user has added additional, custom types
// only set port if no instance name was provided $refreshTypeParser(dataType) {
if (config.dialectOptions.instanceName) { parserStore.refresh(dataType);
delete connectionConfig.options.port; }
}
// The 'tedious' driver needs domain property to be in the main Connection config object $clearTypeParser() {
if(config.dialectOptions.domain) { parserStore.clear();
connectionConfig.domain = config.dialectOptions.domain; }
}
Object.keys(config.dialectOptions).forEach(function(key) { connect(config) {
connectionConfig.options[key] = config.dialectOptions[key]; return new Promise((resolve, reject) => {
}); const connectionConfig = {
} userName: config.username,
password: config.password,
server: config.host,
options: {
port: config.port,
database: config.database
}
};
var connection = new self.lib.Connection(connectionConfig) if (config.dialectOptions) {
, connectionLock = new ResourceLock(connection); // only set port if no instance name was provided
connection.lib = self.lib; if (config.dialectOptions.instanceName) {
delete connectionConfig.options.port;
}
connection.on('connect', function(err) { // The 'tedious' driver needs domain property to be in the main Connection config object
if (!err) { if(config.dialectOptions.domain) {
resolve(connectionLock); connectionConfig.domain = config.dialectOptions.domain;
return; }
}
if (!err.code) { for (const key of Object.keys(config.dialectOptions)) {
reject(new sequelizeErrors.ConnectionError(err)); connectionConfig.options[key] = config.dialectOptions[key];
return; }
} }
switch (err.code) { const connection = new this.lib.Connection(connectionConfig);
case 'ESOCKET': const connectionLock = new ResourceLock(connection);
if (_.includes(err.message, 'connect EHOSTUNREACH')) { connection.lib = this.lib;
reject(new sequelizeErrors.HostNotReachableError(err));
} else if (_.includes(err.message, 'connect ECONNREFUSED')) { connection.on('connect', err => {
reject(new sequelizeErrors.ConnectionRefusedError(err)); if (!err) {
} else { resolve(connectionLock);
return;
}
if (!err.code) {
reject(new sequelizeErrors.ConnectionError(err)); reject(new sequelizeErrors.ConnectionError(err));
return;
} }
break;
case 'ECONNREFUSED':
reject(new sequelizeErrors.ConnectionRefusedError(err));
break;
case 'ER_ACCESS_DENIED_ERROR':
reject(new sequelizeErrors.AccessDeniedError(err));
break;
case 'ENOTFOUND':
reject(new sequelizeErrors.HostNotFoundError(err));
break;
case 'EHOSTUNREACH':
reject(new sequelizeErrors.HostNotReachableError(err));
break;
case 'EINVAL':
reject(new sequelizeErrors.InvalidConnectionError(err));
break;
default:
reject(new sequelizeErrors.ConnectionError(err));
break;
}
});
if (config.pool.handleDisconnects) {
connection.on('error', function (err) {
switch (err.code) { switch (err.code) {
case 'ESOCKET': case 'ESOCKET':
case 'ECONNRESET': if (_.includes(err.message, 'connect EHOSTUNREACH')) {
self.pool.destroy(connectionLock); reject(new sequelizeErrors.HostNotReachableError(err));
} else if (_.includes(err.message, 'connect ECONNREFUSED')) {
reject(new sequelizeErrors.ConnectionRefusedError(err));
} else {
reject(new sequelizeErrors.ConnectionError(err));
}
break;
case 'ECONNREFUSED':
reject(new sequelizeErrors.ConnectionRefusedError(err));
break;
case 'ER_ACCESS_DENIED_ERROR':
reject(new sequelizeErrors.AccessDeniedError(err));
break;
case 'ENOTFOUND':
reject(new sequelizeErrors.HostNotFoundError(err));
break;
case 'EHOSTUNREACH':
reject(new sequelizeErrors.HostNotReachableError(err));
break;
case 'EINVAL':
reject(new sequelizeErrors.InvalidConnectionError(err));
break;
default:
reject(new sequelizeErrors.ConnectionError(err));
break;
} }
}); });
}
});
};
ConnectionManager.prototype.disconnect = function(connectionLock) { if (config.pool.handleDisconnects) {
var connection = connectionLock.unwrap(); connection.on('error', err => {
switch (err.code) {
case 'ESOCKET':
case 'ECONNRESET':
this.pool.destroy(connectionLock);
}
});
}
// Dont disconnect a connection that is already disconnected });
if (!!connection.closed) {
return Promise.resolve();
} }
return new Promise(function (resolve, reject) { disconnect(connectionLock) {
connection.on('end', resolve); const connection = connectionLock.unwrap();
connection.close();
});
};
ConnectionManager.prototype.validate = function(connectionLock) { // Dont disconnect a connection that is already disconnected
var connection = connectionLock.unwrap(); if (!!connection.closed) {
return Promise.resolve();
}
return connection && connection.loggedIn; return new Promise(resolve => {
}; connection.on('end', resolve);
connection.close();
});
}
validate(connectionLock) {
const connection = connectionLock.unwrap();
return connection && connection.loggedIn;
}
}
module.exports = ConnectionManager; module.exports = ConnectionManager;
module.exports.ConnectionManager = ConnectionManager;
module.exports.default = ConnectionManager;
'use strict'; 'use strict';
var Utils = require('../../utils') const Utils = require('../../utils');
, Promise = require('../../promise') const Promise = require('../../promise');
, AbstractQuery = require('../abstract/query') const AbstractQuery = require('../abstract/query');
, sequelizeErrors = require('../../errors.js') const sequelizeErrors = require('../../errors.js');
, parserStore = require('../parserStore')('mssql'), const parserStore = require('../parserStore')('mssql');
_ = require('lodash'); const _ = require('lodash');
var Query = function(connection, sequelize, options) { class Query extends AbstractQuery {
this.connection = connection; constructor(connection, sequelize, options) {
this.instance = options.instance; super();
this.model = options.model; this.connection = connection;
this.sequelize = sequelize; this.instance = options.instance;
this.options = Utils._.extend({ this.model = options.model;
logging: console.log, this.sequelize = sequelize;
plain: false, this.options = Utils._.extend({
raw: false logging: console.log,
}, options || {}); plain: false,
raw: false
this.checkLoggingOption(); }, options || {});
};
this.checkLoggingOption();
Utils.inherit(Query, AbstractQuery);
Query.prototype.getInsertIdField = function() {
return 'id';
};
Query.formatBindParameters = AbstractQuery.formatBindParameters;
Query.prototype._run = function(connection, sql, parameters) {
var self = this;
this.sql = sql;
//do we need benchmark for this query execution
var benchmark = this.sequelize.options.benchmark || this.options.benchmark;
if (benchmark) {
var queryBegin = Date.now();
} else {
this.sequelize.log('Executing (' + (connection.uuid || 'default') + '): ' + this.sql, this.options);
} }
var promise = new Utils.Promise(function(resolve, reject) { getInsertIdField() {
// TRANSACTION SUPPORT return 'id';
if (_.includes(self.sql, 'BEGIN TRANSACTION')) { }
connection.beginTransaction(function(err) {
if (!!err) {
reject(self.formatError(err));
} else {
resolve(self.formatResults());
}
} /* name, isolation_level */);
} else if (_.includes(self.sql, 'COMMIT TRANSACTION')) {
connection.commitTransaction(function(err) {
if (!!err) {
reject(self.formatError(err));
} else {
resolve(self.formatResults());
}
});
} else if (_.includes(self.sql, 'ROLLBACK TRANSACTION')) {
connection.rollbackTransaction(function(err) {
if (!!err) {
reject(self.formatError(err));
} else {
resolve(self.formatResults());
}
});
} else {
// QUERY SUPPORT
var results = [];
var request = new connection.lib.Request(self.sql, function(err) {
if (benchmark) {
self.sequelize.log('Executed (' + (connection.uuid || 'default') + '): ' + self.sql, (Date.now() - queryBegin), self.options);
}
if (err) {
err.sql = sql;
reject(self.formatError(err));
} else {
resolve(self.formatResults(results));
}
});
request.on('row', function(columns) { _run(connection, sql, parameters) {
var row = {}; this.sql = sql;
columns.forEach(function(column) {
var typeid = column.metadata.type.id
, value = column.value
, parse = parserStore.get(typeid);
if (value !== null & !!parse) { //do we need benchmark for this query execution
value = parse(value); const benchmark = this.sequelize.options.benchmark || this.options.benchmark;
let queryBegin;
if (benchmark) {
queryBegin = Date.now();
} else {
this.sequelize.log('Executing (' + (connection.uuid || 'default') + '): ' + this.sql, this.options);
}
return new Promise((resolve, reject) => {
// TRANSACTION SUPPORT
if (_.includes(this.sql, 'BEGIN TRANSACTION')) {
connection.beginTransaction(err => {
if (!!err) {
reject(this.formatError(err));
} else {
resolve(this.formatResults());
}
} /* name, isolation_level */);
} else if (_.includes(this.sql, 'COMMIT TRANSACTION')) {
connection.commitTransaction(err => {
if (!!err) {
reject(this.formatError(err));
} else {
resolve(this.formatResults());
} }
row[column.metadata.colName] = value;
}); });
} else if (_.includes(this.sql, 'ROLLBACK TRANSACTION')) {
connection.rollbackTransaction(err => {
if (!!err) {
reject(this.formatError(err));
} else {
resolve(this.formatResults());
}
});
} else {
// QUERY SUPPORT
const results = [];
results.push(row); const request = new connection.lib.Request(this.sql, err => {
});
connection.execSql(request); if (benchmark) {
} this.sequelize.log('Executed (' + (connection.uuid || 'default') + '): ' + this.sql, (Date.now() - queryBegin), this.options);
}); }
return promise;
};
Query.prototype.run = function(sql, parameters) {
var self = this;
return Promise.using(this.connection.lock(), function (connection) {
return self._run(connection, sql, parameters);
});
};
/**
* High level function that handles the results of a query execution.
*
*
* Example:
* query.formatResults([
* {
* id: 1, // this is from the main table
* attr2: 'snafu', // this is from the main table
* Tasks.id: 1, // this is from the associated table
* Tasks.title: 'task' // this is from the associated table
* }
* ])
*
* @param {Array} data - The result of the query execution.
*/
Query.prototype.formatResults = function(data) {
var result = this.instance;
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data);
if (!this.instance) {
if (this.options.plain) {
// NOTE: super contrived. This just passes the newly added query-interface
// test returning only the PK. There isn't a way in MSSQL to identify
// that a given return value is the PK, and we have no schema information
// because there was no calling Model.
var record = data[0];
result = record[Object.keys(record)[0]];
} else {
result = data;
}
}
}
if (this.isShowTablesQuery()) { if (err) {
result = this.handleShowTablesQuery(data); err.sql = sql;
} else if (this.isDescribeQuery()) { reject(this.formatError(err));
result = {}; } else {
data.forEach(function(_result) { resolve(this.formatResults(results));
if (_result.Default) { }
_result.Default = _result.Default.replace("('",'').replace("')",'').replace(/'/g,''); /* jshint ignore: line */ });
}
result[_result.Name] = { request.on('row', columns => {
type: _result.Type.toUpperCase(), const row = {};
allowNull: (_result.IsNull === 'YES' ? true : false), for (const column of columns) {
defaultValue: _result.Default, const typeid = column.metadata.type.id;
primaryKey: _result.Constraint === 'PRIMARY KEY' const parse = parserStore.get(typeid);
}; let value = column.value;
if (value !== null & !!parse) {
value = parse(value);
}
row[column.metadata.colName] = value;
}
results.push(row);
});
connection.execSql(request);
}
}); });
} else if (this.isShowIndexesQuery()) { }
result = this.handleShowIndexesQuery(data);
} else if (this.isSelectQuery()) { run(sql, parameters) {
result = this.handleSelectQuery(data); return Promise.using(this.connection.lock(), connection => this._run(connection, sql, parameters));
} else if (this.isCallQuery()) { }
result = data[0];
} else if (this.isBulkUpdateQuery()) { /**
result = data.length; * High level function that handles the results of a query execution.
} else if (this.isBulkDeleteQuery()){ *
result = data[0] && data[0].AFFECTEDROWS; *
} else if (this.isVersionQuery()) { * Example:
result = data[0].version; * query.formatResults([
} else if (this.isForeignKeysQuery()) { * {
result = data; * id: 1, // this is from the main table
} else if (this.isRawQuery()) { * attr2: 'snafu', // this is from the main table
// MSSQL returns row data and metadata (affected rows etc) in a single object - let's standarize it, sorta * Tasks.id: 1, // this is from the associated table
result = [data, data]; * Tasks.title: 'task' // this is from the associated table
} * }
* ])
return result; *
}; * @param {Array} data - The result of the query execution.
*/
Query.prototype.handleShowTablesQuery = function(results) { formatResults(data) {
return results.map(function(resultSet) { let result = this.instance;
return { if (this.isInsertQuery(data)) {
tableName: resultSet.TABLE_NAME, this.handleInsertQuery(data);
schema: resultSet.TABLE_SCHEMA
}; if (!this.instance) {
}); if (this.options.plain) {
}; // NOTE: super contrived. This just passes the newly added query-interface
// test returning only the PK. There isn't a way in MSSQL to identify
Query.prototype.formatError = function (err) { // that a given return value is the PK, and we have no schema information
var match; // because there was no calling Model.
const record = data[0];
match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'.(:? The duplicate key value is \((.*)\).)?/); result = record[Object.keys(record)[0]];
match = match || err.message.match(/Cannot insert duplicate key row in object .* with unique index '(.*)'/); } else {
if (match && match.length > 1) { result = data;
var fields = {} }
, message = 'Validation error'
, uniqueKey = this.model && this.model.uniqueKeys[match[1]];
if (uniqueKey && !!uniqueKey.msg) {
message = uniqueKey.msg;
}
if (!!match[4]) {
var values = match[4].split(',').map(Function.prototype.call, String.prototype.trim);
if (!!uniqueKey) {
fields = Utils._.zipObject(uniqueKey.fields, values);
} else {
fields[match[1]] = match[4];
} }
} }
var errors = []; if (this.isShowTablesQuery()) {
var self = this; result = this.handleShowTablesQuery(data);
Utils._.forOwn(fields, function(value, field) { } else if (this.isDescribeQuery()) {
errors.push(new sequelizeErrors.ValidationErrorItem( result = {};
self.getUniqueConstraintErrorMessage(field), for (const _result of data) {
'unique violation', field, value)); if (_result.Default) {
}); _result.Default = _result.Default.replace("('",'').replace("')",'').replace(/'/g,''); /* jshint ignore: line */
}
result[_result.Name] = {
type: _result.Type.toUpperCase(),
allowNull: (_result.IsNull === 'YES' ? true : false),
defaultValue: _result.Default,
primaryKey: _result.Constraint === 'PRIMARY KEY'
};
}
} else if (this.isShowIndexesQuery()) {
result = this.handleShowIndexesQuery(data);
} else if (this.isSelectQuery()) {
result = this.handleSelectQuery(data);
} else if (this.isCallQuery()) {
result = data[0];
} else if (this.isBulkUpdateQuery()) {
result = data.length;
} else if (this.isBulkDeleteQuery()){
result = data[0] && data[0].AFFECTEDROWS;
} else if (this.isVersionQuery()) {
result = data[0].version;
} else if (this.isForeignKeysQuery()) {
result = data;
} else if (this.isRawQuery()) {
// MSSQL returns row data and metadata (affected rows etc) in a single object - let's standarize it, sorta
result = [data, data];
}
return new sequelizeErrors.UniqueConstraintError({ return result;
message: message,
errors: errors,
parent: err,
fields: fields
});
} }
match = err.message.match(/Failed on step '(.*)'.Could not create constraint. See previous errors./) || handleShowTablesQuery(results) {
err.message.match(/The DELETE statement conflicted with the REFERENCE constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./) || return results.map(resultSet => {
err.message.match(/The INSERT statement conflicted with the FOREIGN KEY constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./) || return {
err.message.match(/The UPDATE statement conflicted with the FOREIGN KEY constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./); tableName: resultSet.TABLE_NAME,
if (match && match.length > 0) { schema: resultSet.TABLE_SCHEMA
return new sequelizeErrors.ForeignKeyConstraintError({ };
fields: null,
index: match[1],
parent: err
}); });
} }
return new sequelizeErrors.DatabaseError(err); formatError(err) {
}; let match;
match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'.(:? The duplicate key value is \((.*)\).)?/);
match = match || err.message.match(/Cannot insert duplicate key row in object .* with unique index '(.*)'/);
if (match && match.length > 1) {
let fields = {};
const uniqueKey = this.model && this.model.uniqueKeys[match[1]];
let message = 'Validation error';
if (uniqueKey && !!uniqueKey.msg) {
message = uniqueKey.msg;
}
if (!!match[4]) {
const values = match[4].split(',').map(part => part.trim());
if (!!uniqueKey) {
fields = Utils._.zipObject(uniqueKey.fields, values);
} else {
fields[match[1]] = match[4];
}
}
Query.prototype.isShowOrDescribeQuery = function() { const errors = [];
var result = false; Utils._.forOwn(fields, (value, field) => {
errors.push(new sequelizeErrors.ValidationErrorItem(
this.getUniqueConstraintErrorMessage(field),
'unique violation', field, value
));
});
result = result || (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0); /* jshint ignore: line */ return new sequelizeErrors.UniqueConstraintError({message, errors, parent: err, fields});
result = result || (this.sql.toLowerCase().indexOf('select tablename = t.name, name = ind.name,') === 0); }
result = result || (this.sql.toLowerCase().indexOf('exec sys.sp_helpindex @objname') === 0);
return result; match = err.message.match(/Failed on step '(.*)'.Could not create constraint. See previous errors./) ||
}; err.message.match(/The DELETE statement conflicted with the REFERENCE constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./) ||
err.message.match(/The INSERT statement conflicted with the FOREIGN KEY constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./) ||
err.message.match(/The UPDATE statement conflicted with the FOREIGN KEY constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./);
if (match && match.length > 0) {
return new sequelizeErrors.ForeignKeyConstraintError({
fields: null,
index: match[1],
parent: err
});
}
Query.prototype.isShowIndexesQuery = function () { return new sequelizeErrors.DatabaseError(err);
return this.sql.toLowerCase().indexOf('exec sys.sp_helpindex @objname') === 0; }
};
Query.prototype.handleShowIndexesQuery = function (data) { isShowOrDescribeQuery() {
// Group by index name, and collect all fields let result = false;
data = _.reduce(data, function (acc, item) {
if (!(item.index_name in acc)) {
acc[item.index_name] = item;
item.fields = [];
}
Utils._.forEach(item.index_keys.split(','), function(column) { result = result || (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0); /* jshint ignore: line */
var columnName = column.trim(); result = result || (this.sql.toLowerCase().indexOf('select tablename = t.name, name = ind.name,') === 0);
if (columnName.indexOf('(-)') !== -1) { result = result || (this.sql.toLowerCase().indexOf('exec sys.sp_helpindex @objname') === 0);
columnName = columnName.replace('(-)','');
return result;
}
isShowIndexesQuery() {
return this.sql.toLowerCase().indexOf('exec sys.sp_helpindex @objname') === 0;
}
handleShowIndexesQuery(data) {
// Group by index name, and collect all fields
data = _.reduce(data, (acc, item) => {
if (!(item.index_name in acc)) {
acc[item.index_name] = item;
item.fields = [];
} }
acc[item.index_name].fields.push({ Utils._.forEach(item.index_keys.split(','), column => {
attribute: columnName, let columnName = column.trim();
length: undefined, if (columnName.indexOf('(-)') !== -1) {
order: (column.indexOf('(-)') !== -1 ? 'DESC' : 'ASC'), columnName = columnName.replace('(-)','');
collate: undefined }
acc[item.index_name].fields.push({
attribute: columnName,
length: undefined,
order: (column.indexOf('(-)') !== -1 ? 'DESC' : 'ASC'),
collate: undefined
});
}); });
}); delete item.index_keys;
delete item.index_keys; return acc;
return acc; }, {});
}, {});
return Utils._.map(data, function(item) { return Utils._.map(data, item => ({
return {
primary: (item.index_name.toLowerCase().indexOf('pk') === 0), primary: (item.index_name.toLowerCase().indexOf('pk') === 0),
fields: item.fields, fields: item.fields,
name: item.index_name, name: item.index_name,
tableName: undefined, tableName: undefined,
unique: (item.index_description.toLowerCase().indexOf('unique') !== -1), unique: (item.index_description.toLowerCase().indexOf('unique') !== -1),
type: undefined, type: undefined
}; }));
}); }
};
handleInsertQuery(results, metaData) {
Query.prototype.handleInsertQuery = function(results, metaData) { if (this.instance) {
if (this.instance) { // add the inserted row id to the instance
// add the inserted row id to the instance const autoIncrementField = this.model.autoIncrementField;
var autoIncrementField = this.model.autoIncrementField let id = null;
, autoIncrementFieldAlias = null let autoIncrementFieldAlias = null;
, id = null;
if (this.model.rawAttributes.hasOwnProperty(autoIncrementField) &&
if (this.model.rawAttributes.hasOwnProperty(autoIncrementField) && this.model.rawAttributes[autoIncrementField].field !== undefined)
this.model.rawAttributes[autoIncrementField].field !== undefined) autoIncrementFieldAlias = this.model.rawAttributes[autoIncrementField].field ;
autoIncrementFieldAlias = this.model.rawAttributes[autoIncrementField].field ;
id = id || (results && results[0][this.getInsertIdField()]);
id = id || (results && results[0][this.getInsertIdField()]); id = id || (metaData && metaData[this.getInsertIdField()]);
id = id || (metaData && metaData[this.getInsertIdField()]); id = id || (results && results[0][autoIncrementField]);
id = id || (results && results[0][autoIncrementField]); id = id || (autoIncrementFieldAlias && results && results[0][autoIncrementFieldAlias]);
id = id || (autoIncrementFieldAlias && results && results[0][autoIncrementFieldAlias]);
this.instance[autoIncrementField] = id;
this.instance[autoIncrementField] = id; }
} }
}; }
module.exports = Query; module.exports = Query;
module.exports.Query = Query;
module.exports.default = Query;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!