forked from TryGhost/node-sqlite3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.test.js
63 lines (54 loc) · 2.15 KB
/
map.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var sqlite3 = require('..');
var assert = require('assert');
describe('map', function() {
it('test Database#map() with two columns', function(done) {
var count = 10;
var inserted = 0;
var db = new sqlite3.Database(':memory:');
db.serialize(function() {
db.run("CREATE TABLE foo (id INT, value TEXT)");
var stmt = db.prepare("INSERT INTO foo VALUES(?, ?)");
for (var i = 5; i < count; i++) {
stmt.run(i, 'Value for ' + i, function(err) {
if (err) throw err;
inserted++;
});
}
stmt.finalize();
db.map("SELECT * FROM foo", function(err, map) {
if (err) throw err;
assert.deepEqual(map, { 5: 'Value for 5', 6: 'Value for 6', 7: 'Value for 7', 8: 'Value for 8', 9: 'Value for 9' });
assert.equal(inserted, 5);
done();
});
});
});
it('test Database#map() with three columns', function(done) {
var db = new sqlite3.Database(':memory:');
var count = 10;
var inserted = 0;
db.serialize(function() {
db.run("CREATE TABLE foo (id INT, value TEXT, other TEXT)");
var stmt = db.prepare("INSERT INTO foo VALUES(?, ?, ?)");
for (var i = 5; i < count; i++) {
stmt.run(i, 'Value for ' + i, null, function(err) {
if (err) throw err;
inserted++;
});
}
stmt.finalize();
db.map("SELECT * FROM foo", function(err, map) {
if (err) throw err;
assert.deepEqual(map, {
5: { id: 5, value: 'Value for 5', other: null },
6: { id: 6, value: 'Value for 6', other: null },
7: { id: 7, value: 'Value for 7', other: null },
8: { id: 8, value: 'Value for 8', other: null },
9: { id: 9, value: 'Value for 9', other: null }
});
assert.equal(inserted, 5);
done();
});
});
});
});