Skip to content

Commit d183cdc

Browse files
Merge pull request #8 from jouke/master
SQLiteDB.prototype.toDatabase no longer changes object contents when val is an array
2 parents 70a5b36 + 6d55a53 commit d183cdc

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/migration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function mixinMigration(SQLiteDB) {
3030
}
3131

3232
var sql = null;
33-
sql = 'PRAGMA table_info(' + this.table(model) +')';
33+
sql = 'PRAGMA table_info(' + this.tableEscaped(model) +')';
3434
var params = [];
3535
params.status = true;
3636
this.executeSQL(sql, params, decoratedCallback);

lib/sqlite3db.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,11 @@ SQLiteDB.prototype.toDatabase = function (prop, val) {
317317
return this.toDatabase(prop, val[0]) + ' AND ' + this.toDatabase(prop, val[1]);
318318
}
319319
if (operator === 'inq' || operator === 'nin') {
320+
var newVal = [];
320321
for (var i = 0; i < val.length; i++) {
321-
val[i] = escape(val[i]);
322+
newVal[i] = escape(val[i]);
322323
}
323-
return val.join(',');
324+
return newVal.join(',');
324325
}
325326
return this.toDatabase(prop, val);
326327
}

test/user_model.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,29 @@ describe("SQLite Model creation test", function(){
4747
expect(u.name).to.be.equal("John");
4848
else if(u.id == 2) {
4949
expect(u.name).to.be.equal("Doe");
50-
done();
50+
testArrayContents(done)
51+
// done();
5152
}
5253
});
5354
}
55+
56+
function testArrayContents(cb) {
57+
var namesSomething = [{name: 'John', some: 'object'}, {name: 'Doe', some: 'other object'}];
58+
var names = [];
59+
namesSomething.forEach(function(n) {
60+
names.push(n.name);
61+
});
62+
63+
User.find({
64+
where: {
65+
name: {inq: names}
66+
}
67+
}, function(err, foundUsers) {
68+
expect(names[0]).to.be.equal('John');
69+
expect(names[1]).to.be.equal('Doe');
70+
cb();
71+
});
72+
}
5473
});
5574

5675
it('should run auto-migration when model changes', function (done) {

0 commit comments

Comments
 (0)