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

Commit 99d83343 by sdepold

sqlite extends mysql now

1 parent 7c3df785
Showing with 6 additions and 55 deletions
...@@ -25,64 +25,10 @@ module.exports = (function() { ...@@ -25,64 +25,10 @@ module.exports = (function() {
return Utils._.template(query)(values).trim() + ";" return Utils._.template(query)(values).trim() + ";"
}, },
dropTableQuery: function(tableName, options) {
options = options || {}
var query = "DROP TABLE IF EXISTS <%= table %>;"
return Utils._.template(query)({table: Utils.addTicks(tableName)})
},
showTablesQuery: function() { showTablesQuery: function() {
return "SELECT name FROM sqlite_master WHERE type='table';" return "SELECT name FROM sqlite_master WHERE type='table';"
}, },
selectQuery: function(tableName, options) {
options = options || {}
options.table = Utils.addTicks(tableName)
options.attributes = options.attributes && options.attributes.map(function(attr){
if(Array.isArray(attr) && attr.length == 2)
return [attr[0], Utils.addTicks(attr[1])].join(' as ')
else
return Utils.addTicks(attr)
}).join(", ")
options.attributes = options.attributes || '*'
var query = "SELECT <%= attributes %> FROM <%= table %>"
if(options.where) {
options.where = QueryGenerator.getWhereConditions(options.where)
query += " WHERE <%= where %>"
}
if(options.order) query += " ORDER BY <%= order %>"
if(options.group) {
options.group = Utils.addTicks(options.group)
query += " GROUP BY <%= group %>"
}
if(options.limit) {
if(options.offset) query += " LIMIT <%= offset %>, <%= limit %>"
else query += " LIMIT <%= limit %>"
}
query += ";"
return Utils._.template(query)(options)
},
insertQuery: function(tableName, attrValueHash) {
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
var replacements = {
table: Utils.addTicks(tableName),
attributes: Utils._.keys(attrValueHash).map(function(attr){return Utils.addTicks(attr)}).join(","),
values: Utils._.values(attrValueHash).map(function(value){
return Utils.escape((value instanceof Date) ? Utils.toSqlDate(value) : value)
}).join(",")
}
return Utils._.template(query)(replacements)
},
attributesToSQL: function(attributes) { attributesToSQL: function(attributes) {
var result = {} var result = {}
...@@ -112,5 +58,10 @@ module.exports = (function() { ...@@ -112,5 +58,10 @@ module.exports = (function() {
} }
} }
return Utils._.extend(Utils._.clone(require("../query-generator")), QueryGenerator) var MySqlQueryGenerator = Utils._.extend(
Utils._.clone(require("../query-generator")),
Utils._.clone(require("../mysql/query-generator"))
)
return Utils._.extend(MySqlQueryGenerator, QueryGenerator)
})() })()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!