forked from journeyapps/node-sqlcipher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamed_params.test.js
69 lines (60 loc) · 2.32 KB
/
named_params.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
64
65
66
67
68
69
var sqlite3 = require('..');
var assert = require('assert');
describe('named parameters', function() {
var db;
before(function(done) {
db = new sqlite3.Database(':memory:', done);
});
it('should create the table', function(done) {
db.run("CREATE TABLE foo (txt TEXT, num INT)", done);
});
it('should insert a value with $ placeholders', function(done) {
db.run("INSERT INTO foo VALUES($text, $id)", {
$id: 1,
$text: "Lorem Ipsum"
}, done);
});
it('should insert a value with : placeholders', function(done) {
db.run("INSERT INTO foo VALUES(:text, :id)", {
':id': 2,
':text': "Dolor Sit Amet"
}, done);
});
it('should insert a value with @ placeholders', function(done) {
db.run("INSERT INTO foo VALUES(@txt, @id)", {
"@id": 3,
"@txt": "Consectetur Adipiscing Elit"
}, done);
});
it('should insert a value with @ placeholders using an array', function(done) {
db.run("INSERT INTO foo VALUES(@txt, @id)", [ 'Sed Do Eiusmod', 4 ], done);
});
it('should insert a value with indexed placeholders', function(done) {
db.run("INSERT INTO foo VALUES(?2, ?4)",
[ null, 'Tempor Incididunt', null, 5 ], done);
});
it('should insert a value with autoindexed placeholders', function(done) {
db.run("INSERT INTO foo VALUES(?, ?)", {
2: 6,
1: "Ut Labore Et Dolore"
}, done);
});
it('should retrieve all inserted values', function(done) {
db.all("SELECT txt, num FROM foo ORDER BY num", function(err, rows) {
if (err) throw err;
assert.equal(rows[0].txt, "Lorem Ipsum");
assert.equal(rows[0].num, 1);
assert.equal(rows[1].txt, "Dolor Sit Amet");
assert.equal(rows[1].num, 2);
assert.equal(rows[2].txt, "Consectetur Adipiscing Elit");
assert.equal(rows[2].num, 3);
assert.equal(rows[3].txt, "Sed Do Eiusmod");
assert.equal(rows[3].num, 4);
assert.equal(rows[4].txt, "Tempor Incididunt");
assert.equal(rows[4].num, 5);
assert.equal(rows[5].txt, "Ut Labore Et Dolore");
assert.equal(rows[5].num, 6);
done();
});
});
});