forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.spec.js
More file actions
43 lines (33 loc) · 1.23 KB
/
index.spec.js
File metadata and controls
43 lines (33 loc) · 1.23 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
const { expect } = require('chai');
const Parser = require('../src/parser').default
describe('MariaDB Command SQL', () => {
const parser = new Parser();
function getParsedSql(sql, opt) {
const ast = parser.astify(sql, opt);
return parser.sqlify(ast, opt);
}
it('unknow database', () => {
const sql = 'select id from db.abc'
const opt = { database: 'unknownDB' }
expect(parser.parse.bind(parser, sql, opt)).to.throw(`${opt.database} is not supported currently`)
})
describe('blank line or whitespace auto remove', () => {
const sql = `
CALL utility.create_backup_script(schemaName, 'table_name', 'ticket_name');
DELETE FROM table_name WHERE id = 0;
`
it('should support blank line', () => {
const ast = parser.parse(sql)
expect(ast.ast.length).to.be.equal(2)
})
})
describe('different quota based on database', () => {
const sql = 'select id, "name" from db.abc'
it('support pg to double quote', () => {
expect(getParsedSql(sql, { database: 'PostgresQL'})).to.equal('SELECT id, "name" FROM "db"."abc"')
})
it('support mariadb quote', () => {
expect(getParsedSql(sql, { database: 'MariaDB'})).to.equal('SELECT `id`, "name" FROM `db`.`abc`')
})
})
})