1. 1var sqlite3 = require('..');
2. 1var assert = require('assert');
3. 1
4. 1describe('named parameters', function() {
5. 1 var db;
6. 1 before(function(done) {
7. 1 db = new sqlite3.Database(':memory:', done);
8. 1 });
9. 1
10. 1 it('should create the table', function(done) {
11. 1 db.run("CREATE TABLE foo (txt TEXT, num INT)", done);
12. 1 });
13. 1
14. 1 it('should insert a value with $ placeholders', function(done) {
15. 1 db.run("INSERT INTO foo VALUES($text, $id)", {
16. 1 $id: 1,
17. 1 $text: "Lorem Ipsum"
18. 1 }, done);
19. 1 });
20. 1
21. 1 it('should insert a value with : placeholders', function(done) {
22. 1 db.run("INSERT INTO foo VALUES(:text, :id)", {
23. 1 ':id': 2,
24. 1 ':text': "Dolor Sit Amet"
25. 1 }, done);
26. 1 });
27. 1
28. 1 it('should insert a value with @ placeholders', function(done) {
29. 1 db.run("INSERT INTO foo VALUES(@txt, @id)", {
30. 1 "@id": 3,
31. 1 "@txt": "Consectetur Adipiscing Elit"
32. 1 }, done);
33. 1 });
34. 1
35. 1 it('should insert a value with @ placeholders using an array', function(done) {
36. 1 db.run("INSERT INTO foo VALUES(@txt, @id)", [ 'Sed Do Eiusmod', 4 ], done);
37. 1 });
38. 1
39. 1 it('should insert a value with indexed placeholders', function(done) {
40. 1 db.run("INSERT INTO foo VALUES(?2, ?4)",
41. 1 [ null, 'Tempor Incididunt', null, 5 ], done);
42. 1 });
43. 1
44. 1 it('should insert a value with autoindexed placeholders', function(done) {
45. 1 db.run("INSERT INTO foo VALUES(?, ?)", {
46. 1 2: 6,
47. 1 1: "Ut Labore Et Dolore"
48. 1 }, done);
49. 1 });
50. 1
51. 1 it('should retrieve all inserted values', function(done) {
52. 1 db.all("SELECT txt, num FROM foo ORDER BY num", function(err, rows) {
53. 0 if (err) throw err;
54. 1 assert.equal(rows[0].txt, "Lorem Ipsum");
55. 1 assert.equal(rows[0].num, 1);
56. 1 assert.equal(rows[1].txt, "Dolor Sit Amet");
57. 1 assert.equal(rows[1].num, 2);
58. 1 assert.equal(rows[2].txt, "Consectetur Adipiscing Elit");
59. 1 assert.equal(rows[2].num, 3);
60. 1 assert.equal(rows[3].txt, "Sed Do Eiusmod");
61. 1 assert.equal(rows[3].num, 4);
62. 1 assert.equal(rows[4].txt, "Tempor Incididunt");
63. 1 assert.equal(rows[4].num, 5);
64. 1 assert.equal(rows[5].txt, "Ut Labore Et Dolore");
65. 1 assert.equal(rows[5].num, 6);
66. 1 done();
67. 1 });
68. 1 });
69. 1});
70. 1