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

Commit 89c2211d by sdepold

extracted showTablesQuery

1 parent 8c519107
......@@ -43,6 +43,10 @@ module.exports = (function() {
return Utils._.template(query)({ before: before, after: after })
},
showTablesQuery: function() {
return 'SHOW TABLES;'
},
addColumnQuery: function(tableName, attributes) {
var query = "ALTER TABLE `<%= tableName %>` ADD <%= attributes %>;"
, attrString = Utils._.map(attributes, function(definition, attributeName) {
......
......@@ -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.
Parameters:
- tableName: Name of the existing table.
......@@ -194,7 +201,7 @@ module.exports = (function() {
}
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
......
......@@ -54,11 +54,8 @@ module.exports = (function() {
var self = this
return new Utils.CustomEventEmitter(function(emitter) {
self.sequelize.query('SHOW TABLES;', null, { raw: true }).success(function(data) {
var tableNames = Sequelize.Utils._.map(data, function(hash) {
return Sequelize.Utils._.values(hash)
})
var showTablesSql = self.QueryGenerator.showTablesQuery()
self.sequelize.query(showTablesSql, null, { raw: true }).success(function(tableNames) {
self.emit('showAllTables', null)
emitter.emit('success', Sequelize.Utils._.flatten(tableNames))
}).error(function(err) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!