-
-
Notifications
You must be signed in to change notification settings - Fork 829
/
Copy pathnamed_columns.test.js
38 lines (32 loc) · 1.06 KB
/
named_columns.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
var sqlite3 = require('..');
var assert = require('assert');
describe('named columns', 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', function(done) {
db.run("INSERT INTO foo VALUES($text, $id)", {
$id: 1,
$text: "Lorem Ipsum"
}, done);
});
it('should retrieve the values', function(done) {
db.get("SELECT txt, num FROM foo ORDER BY num", function(err, row) {
if (err) throw err;
assert.equal(row.txt, "Lorem Ipsum");
assert.equal(row.num, 1);
done();
});
});
it('should be able to retrieve rowid of last inserted value', function(done) {
db.get("SELECT last_insert_rowid() as last_id FROM foo", function(err, row) {
if (err) throw err;
assert.equal(row.last_id, 1);
done();
});
});
});