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

Commit 7b8d0b76 by Matt Broadstone

add QueryTypes.SHOWTABLES

Refactor checking for a SHOW TABLES query so that we're no longer
doing a string comparison to determine this query type.
1 parent 263ddba0
...@@ -123,11 +123,11 @@ module.exports = (function() { ...@@ -123,11 +123,11 @@ module.exports = (function() {
} }
}; };
AbstractQuery.prototype.isShowTableQuery = function() { AbstractQuery.prototype.isShowTablesQuery = function() {
return (this.sql.toLowerCase().indexOf('show tables') === 0); return this.options.type === QueryTypes.SHOWTABLES;
}; };
AbstractQuery.prototype.handleShowTableQuery = function(results) { AbstractQuery.prototype.handleShowTablesQuery = function(results) {
return Utils._.flatten(results.map(function(resultSet) { return Utils._.flatten(results.map(function(resultSet) {
return Utils._.values(resultSet); return Utils._.values(resultSet);
})); }));
......
...@@ -123,8 +123,8 @@ module.exports = (function() { ...@@ -123,8 +123,8 @@ module.exports = (function() {
} }
} }
if (this.isShowTableQuery()) { if (this.isShowTablesQuery()) {
result = this.handleShowTableQuery(data); result = this.handleShowTablesQuery(data);
} else if (this.isShowOrDescribeQuery()) { } else if (this.isShowOrDescribeQuery()) {
result = data; result = data;
if (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0) { if (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0) {
...@@ -157,10 +157,6 @@ module.exports = (function() { ...@@ -157,10 +157,6 @@ module.exports = (function() {
return result; return result;
}; };
Query.prototype.isShowTableQuery = function() {
return (this.sql.toLowerCase().indexOf('select name from sys.tables') === 0);
};
Query.prototype.formatError = function (err) { Query.prototype.formatError = function (err) {
var match; var match;
match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'. The duplicate key value is \((.*)\)./); match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'. The duplicate key value is \((.*)\)./);
......
...@@ -75,8 +75,8 @@ module.exports = (function() { ...@@ -75,8 +75,8 @@ module.exports = (function() {
if (this.isSelectQuery()) { if (this.isSelectQuery()) {
result = this.handleSelectQuery(data); result = this.handleSelectQuery(data);
} else if (this.isShowTableQuery()) { } else if (this.isShowTablesQuery()) {
result = this.handleShowTableQuery(data); result = this.handleShowTablesQuery(data);
} else if (this.isShowOrDescribeQuery()) { } else if (this.isShowOrDescribeQuery()) {
result = data; result = data;
......
...@@ -163,7 +163,7 @@ module.exports = (function() { ...@@ -163,7 +163,7 @@ module.exports = (function() {
schema: options.schema schema: options.schema
}); });
} }
attributes = self.QueryGenerator.attributesToSQL(attributes, { attributes = self.QueryGenerator.attributesToSQL(attributes, {
context: 'createTable' context: 'createTable'
}); });
...@@ -286,11 +286,11 @@ module.exports = (function() { ...@@ -286,11 +286,11 @@ module.exports = (function() {
var self = this; var self = this;
options = Utils._.extend({ options = Utils._.extend({
transaction: null, transaction: null,
raw: true raw: true,
type: QueryTypes.SHOWTABLES
}, options || {}); }, options || {});
var showTablesSql = self.QueryGenerator.showTablesQuery(); var showTablesSql = self.QueryGenerator.showTablesQuery();
return self.sequelize.query(showTablesSql, null, options).then(function(tableNames) { return self.sequelize.query(showTablesSql, null, options).then(function(tableNames) {
return Utils._.flatten(tableNames); return Utils._.flatten(tableNames);
}); });
...@@ -605,7 +605,7 @@ module.exports = (function() { ...@@ -605,7 +605,7 @@ module.exports = (function() {
dao[cascades[i]]().success(function(tasks) { dao[cascades[i]]().success(function(tasks) {
if (tasks === null || tasks.length < 1) { if (tasks === null || tasks.length < 1) {
if (i >= cascades.length) { if (i >= cascades.length) {
return resolve(); return resolve();
} else { } else {
tick++; tick++;
return iterate(null, tick); return iterate(null, tick);
......
...@@ -6,5 +6,6 @@ module.exports = { ...@@ -6,5 +6,6 @@ module.exports = {
BULKUPDATE: 'BULKUPDATE', BULKUPDATE: 'BULKUPDATE',
BULKDELETE: 'BULKDELETE', BULKDELETE: 'BULKDELETE',
UPSERT: 'UPSERT', UPSERT: 'UPSERT',
VERSION: 'VERSION' VERSION: 'VERSION',
SHOWTABLES: 'SHOWTABLES'
}; };
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!