sqlite-master.test.js
2.1 KB
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
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../../support'),
dialect = Support.getTestDialect(),
DataTypes = require(__dirname + '/../../../../lib/data-types');
if (dialect === 'sqlite') {
describe('[SQLITE Specific] sqlite_master raw queries', () => {
beforeEach(function() {
this.sequelize.define('SomeTable', {
someColumn: DataTypes.INTEGER
}, {
freezeTableName: true,
timestamps: false
});
return this.sequelize.sync({ force: true });
});
it('should be able to select with tbl_name filter', function() {
return this.sequelize.query('SELECT * FROM sqlite_master WHERE tbl_name=\'SomeTable\'')
.then(result => {
const rows = result[0];
expect(rows).to.have.length(1);
const row = rows[0];
expect(row).to.have.property('type', 'table');
expect(row).to.have.property('name', 'SomeTable');
expect(row).to.have.property('tbl_name', 'SomeTable');
expect(row).to.have.property('sql');
});
});
it('should be able to select *', function() {
return this.sequelize.query('SELECT * FROM sqlite_master')
.then(result => {
const rows = result[0];
expect(rows).to.have.length(2);
rows.forEach(row => {
expect(row).to.have.property('type');
expect(row).to.have.property('name');
expect(row).to.have.property('tbl_name');
expect(row).to.have.property('rootpage');
expect(row).to.have.property('sql');
});
});
});
it('should be able to select just "sql" column and get rows back', function() {
return this.sequelize.query('SELECT sql FROM sqlite_master WHERE tbl_name=\'SomeTable\'')
.then(result => {
const rows = result[0];
expect(rows).to.have.length(1);
const row = rows[0];
expect(row).to.have.property('sql',
'CREATE TABLE `SomeTable` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `someColumn` INTEGER)');
});
});
});
}