sqlite-master.test.js
1.94 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
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require('../../support'),
dialect = Support.getTestDialect(),
DataTypes = require('../../../../lib/data-types');
if (dialect === 'sqlite') {
describe('[SQLITE Specific] sqlite_master raw queries', () => {
beforeEach(async function() {
this.sequelize.define('SomeTable', {
someColumn: DataTypes.INTEGER
}, {
freezeTableName: true,
timestamps: false
});
await this.sequelize.sync({ force: true });
});
it('should be able to select with tbl_name filter', async function() {
const result = await this.sequelize.query('SELECT * FROM sqlite_master WHERE tbl_name=\'SomeTable\'');
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 *', async function() {
const result = await this.sequelize.query('SELECT * FROM sqlite_master');
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', async function() {
const result = await this.sequelize.query('SELECT sql FROM sqlite_master WHERE tbl_name=\'SomeTable\'');
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)');
});
});
}