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

Commit 89c2211d by sdepold

extracted showTablesQuery

1 parent 8c519107
...@@ -43,6 +43,10 @@ module.exports = (function() { ...@@ -43,6 +43,10 @@ module.exports = (function() {
return Utils._.template(query)({ before: before, after: after }) return Utils._.template(query)({ before: before, after: after })
}, },
showTablesQuery: function() {
return 'SHOW TABLES;'
},
addColumnQuery: function(tableName, attributes) { addColumnQuery: function(tableName, attributes) {
var query = "ALTER TABLE `<%= tableName %>` ADD <%= attributes %>;" var query = "ALTER TABLE `<%= tableName %>` ADD <%= attributes %>;"
, attrString = Utils._.map(attributes, function(definition, attributeName) { , attrString = Utils._.map(attributes, function(definition, attributeName) {
......
...@@ -26,6 +26,13 @@ module.exports = (function() { ...@@ -26,6 +26,13 @@ module.exports = (function() {
}, },
/* /*
Returns a query, which gets all available table names in the database.
*/
showTablesQuery: function() {
throwMethodUndefined('showTablesQuery')
},
/*
Returns a query, which adds an attribute to an existing table. Returns a query, which adds an attribute to an existing table.
Parameters: Parameters:
- tableName: Name of the existing table. - tableName: Name of the existing table.
...@@ -194,7 +201,7 @@ module.exports = (function() { ...@@ -194,7 +201,7 @@ module.exports = (function() {
} }
var throwMethodUndefined = function(methodName) { var throwMethodUndefined = function(methodName) {
throw new Error('The method "' + methodName + '" was not defined!') throw new Error('The method "' + methodName + '" is not defined! Please add it to your sql dialect.')
} }
return QueryGenerator return QueryGenerator
......
...@@ -54,11 +54,8 @@ module.exports = (function() { ...@@ -54,11 +54,8 @@ module.exports = (function() {
var self = this var self = this
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
self.sequelize.query('SHOW TABLES;', null, { raw: true }).success(function(data) { var showTablesSql = self.QueryGenerator.showTablesQuery()
var tableNames = Sequelize.Utils._.map(data, function(hash) { self.sequelize.query(showTablesSql, null, { raw: true }).success(function(tableNames) {
return Sequelize.Utils._.values(hash)
})
self.emit('showAllTables', null) self.emit('showAllTables', null)
emitter.emit('success', Sequelize.Utils._.flatten(tableNames)) emitter.emit('success', Sequelize.Utils._.flatten(tableNames))
}).error(function(err) { }).error(function(err) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!