|
10 | 10 | const db = require('../build/main');
|
11 | 11 | const expect = require('chai').expect;
|
12 | 12 |
|
13 |
| -it('Should open a database connection', (done) => { |
14 |
| - let p = db.open(':memory:'); |
15 |
| - p = p.then(() => db.exec('CREATE TABLE tbl (col TEXT)')); |
16 |
| - p = p.then(() => db.exec('INSERT INTO tbl VALUES ("test")')); |
17 |
| - p = p.then(() => db.get('SELECT col FROM tbl').then((result) => { |
18 |
| - expect(result).to.be.deep.equal({ col: 'test' }); |
19 |
| - })); |
20 |
| - p = p.then(() => db.all('SELECT col FROM tbl').then((result) => { |
21 |
| - expect(result).to.be.deep.equal([{ col: 'test' }]); |
22 |
| - })); |
23 |
| - p = p.then(() => db.all('SELECT * FROM tbl WHERE col = ?', 'test').then((result) => { |
24 |
| - expect(result).to.have.length(1); |
25 |
| - })); |
26 |
| - p = p.then(() => db.run('UPDATE tbl SET col = ? WHERE col = ?', 'foo', 'test')).then((stmt) => { |
27 |
| - // Cannot use deep equals because stmt is a Statement instance |
28 |
| - expect(stmt.lastID).to.equal(1); |
29 |
| - expect(stmt.changes).to.equal(1); |
30 |
| - expect(stmt.sql).to.equal('UPDATE tbl SET col = ? WHERE col = ?'); |
| 13 | +// enable the sqlite cached database or not |
| 14 | +const cache = [false, true]; |
| 15 | + |
| 16 | +cache.forEach((c) => { |
| 17 | + it(`Should open a database connection; cached = ${c}`, (done) => { |
| 18 | + let p = db.open(':memory:', { cached: c }); |
| 19 | + p = p.then(() => db.exec('CREATE TABLE tbl (col TEXT)')); |
| 20 | + p = p.then(() => db.exec('INSERT INTO tbl VALUES ("test")')); |
| 21 | + p = p.then(() => db.get('SELECT col FROM tbl').then((result) => { |
| 22 | + expect(result).to.be.deep.equal({ col: 'test' }); |
| 23 | + })); |
| 24 | + p = p.then(() => db.all('SELECT col FROM tbl').then((result) => { |
| 25 | + expect(result).to.be.deep.equal([{ col: 'test' }]); |
| 26 | + })); |
| 27 | + p = p.then(() => db.all('SELECT * FROM tbl WHERE col = ?', 'test').then((result) => { |
| 28 | + expect(result).to.have.length(1); |
| 29 | + })); |
| 30 | + p = p.then(() => db.run('UPDATE tbl SET col = ? WHERE col = ?', 'foo', 'test')).then((stmt) => { |
| 31 | + // Cannot use deep equals because stmt is a Statement instance |
| 32 | + expect(stmt.lastID).to.equal(1); |
| 33 | + expect(stmt.changes).to.equal(1); |
| 34 | + expect(stmt.sql).to.equal('UPDATE tbl SET col = ? WHERE col = ?'); |
| 35 | + }); |
| 36 | + p = p.then(() => db.get('SELECT col FROM tbl').then((result) => { |
| 37 | + expect(result).to.be.deep.equal({ col: 'foo' }); |
| 38 | + })); |
| 39 | + p = p.then(() => db.close()); |
| 40 | + p.then(done, done); |
31 | 41 | });
|
32 |
| - p = p.then(() => db.get('SELECT col FROM tbl').then((result) => { |
33 |
| - expect(result).to.be.deep.equal({ col: 'foo' }); |
34 |
| - })); |
35 |
| - p = p.then(() => db.close()); |
36 |
| - p.then(done, done); |
37 | 42 | });
|
38 | 43 |
|
39 | 44 | it('Should allow named parameters to be used', (done) => {
|
|
0 commit comments