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

Commit 4d17304a by Michael Schonfeld

add insert pr ignore support for sqlite + tests

1 parent 3b9faacf
...@@ -172,8 +172,8 @@ module.exports = (function() { ...@@ -172,8 +172,8 @@ module.exports = (function() {
return "SELECT name FROM sqlite_master WHERE type='table' and name!='sqlite_sequence';" return "SELECT name FROM sqlite_master WHERE type='table' and name!='sqlite_sequence';"
}, },
bulkInsertQuery: function(tableName, attrValueHashes) { bulkInsertQuery: function(tableName, attrValueHashes, options) {
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %>;" var query = "INSERT<%= ignore %> INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %>;"
, tuples = [] , tuples = []
, allAttributes = [] , allAttributes = []
...@@ -192,6 +192,7 @@ module.exports = (function() { ...@@ -192,6 +192,7 @@ module.exports = (function() {
}.bind(this)) }.bind(this))
var replacements = { var replacements = {
ignore: options && options.ignore ? ' OR IGNORE' : '',
table: this.quoteIdentifier(tableName), table: this.quoteIdentifier(tableName),
attributes: allAttributes.map(function(attr){ attributes: allAttributes.map(function(attr){
return this.quoteIdentifier(attr) return this.quoteIdentifier(attr)
......
...@@ -385,6 +385,9 @@ if (dialect === 'sqlite') { ...@@ -385,6 +385,9 @@ if (dialect === 'sqlite') {
arguments: ['myTable', [{name: 'foo', foo: 1, nullValue: null}, {name: 'bar', foo: 2, nullValue: null}]], arguments: ['myTable', [{name: 'foo', foo: 1, nullValue: null}, {name: 'bar', foo: 2, nullValue: null}]],
expectation: "INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',2,NULL);", expectation: "INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',2,NULL);",
context: {options: {omitNull: true}} // Note: As above context: {options: {omitNull: true}} // Note: As above
}, {
arguments: ['myTable', [{name: 'foo'}, {name: 'bar'}], {ignore: true}],
expectation: "INSERT OR IGNORE INTO `myTable` (`name`) VALUES ('foo'),('bar');"
} }
], ],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!