Skip to content

Commit 00fa606

Browse files
committed
test for sqlite query options
1 parent 87e0926 commit 00fa606

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/node_modules
22
*.sw?
3-
test/test.sql
3+
test/test.db

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ db.query(sql, parameters, [options])
557557
```
558558
559559
* SQLite3
560-
`exec` runs the `exec()` method on the connection, see [exec](https://github.com/mapbox/node-sqlite3/wiki/API#databaseexecsql-callback). Note that this method ignores any query `parameters` passed in.
560+
* `multiline` or `exec` runs the `exec()` method on the connection which executes multiple lines, see [exec](https://github.com/mapbox/node-sqlite3/wiki/API#databaseexecsql-callback). Note that this method ignores any query `parameters` passed in.
561561
562562
# Development
563563

sqliteDriver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ module.exports = function() {
1919
if (options && (options.statement || options.insert)) {
2020
return new Promise(function (fulfil, reject) {
2121
debug(query, sqliteParams);
22-
self.connection.run(query, sqliteParams, function (error, result) {
22+
self.connection.run(query, sqliteParams, function (error) {
2323
if (error) {
2424
reject(error);
2525
} else {
2626
fulfil({lastId: this.lastID});
2727
}
2828
});
2929
});
30-
} else if (options && options.exec) {
30+
} else if (options && (options.exec || options.multiline)) {
3131
return promisify(function (cb) {
3232
debug(query, sqliteParams);
3333
self.connection.exec(query, cb);

test/describeDatabase.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var chaiAsPromised = require("chai-as-promised");
66
chai.use(chaiAsPromised);
77
var _ = require("underscore");
88

9-
module.exports = function(name, config, database) {
9+
module.exports = function(name, config, database, otherTests) {
1010
describe(name, function() {
1111
describe("missing modules", function() {
1212
var moduleName = __dirname + "/../node_modules/" + database.driverModuleName;
@@ -52,6 +52,10 @@ module.exports = function(name, config, database) {
5252
}));
5353
}
5454

55+
if (otherTests) {
56+
otherTests();
57+
}
58+
5559
beforeEach(function() {
5660
db = sworm.db(config);
5761
statements = [];

test/sqliteSpec.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var describeDatabase = require('./describeDatabase');
2+
var expect = require('chai').expect;
3+
var sworm = require('..');
24

35
var database = {
46
createTables: function(db, tables) {
@@ -55,7 +57,30 @@ var database = {
5557
driverModuleName: "sqlite3"
5658
};
5759

58-
describeDatabase("sqlite", {
60+
var config = {
5961
driver: "sqlite",
6062
config: { filename: __dirname + "/test.db" }
61-
}, database);
63+
};
64+
65+
describeDatabase("sqlite", config, database, function () {
66+
describe('options', function () {
67+
it.only('can pass options to query', function () {
68+
var db = sworm.db(config);
69+
70+
return db.query('delete from blah').then(() => {
71+
return db.query(`
72+
create table if not exists blah ( x integer not null, y integer not null );
73+
insert into blah (x, y) values (1, 2);
74+
insert into blah (x, y) values (2, 3);
75+
`, {}, {multiline: true});
76+
}).then(() => {
77+
return db.query('select * from blah').then(rows => {
78+
expect(rows).to.eql([
79+
{ x: 1, y: 2 },
80+
{ x: 2, y: 3 }
81+
]);
82+
});
83+
});
84+
});
85+
});
86+
});

0 commit comments

Comments
 (0)