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

Commit 7c3df785 by sdepold

fixed spec + added selectQuery to sqlite

1 parent f18ddbd1
...@@ -37,6 +37,38 @@ module.exports = (function() { ...@@ -37,6 +37,38 @@ module.exports = (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) { insertQuery: function(tableName, attrValueHash) {
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);" var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
......
...@@ -33,6 +33,7 @@ describe('ModelFactory', function() { ...@@ -33,6 +33,7 @@ describe('ModelFactory', function() {
return user.name return user.name
}) })
expect(usernames).toEqual(['John Wayne']) expect(usernames).toEqual(['John Wayne'])
done()
}).error(function(err){ console.log(err) }) }).error(function(err){ console.log(err) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!