forked from florajs/sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.js
More file actions
38 lines (32 loc) · 1.42 KB
/
Copy pathselect.js
File metadata and controls
38 lines (32 loc) · 1.42 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
'use strict';
const { expect } = require('chai');
const { getParsedSql } = require('./util');
describe('select', () => {
it('should parse ANSI SQL compliant statements', () => {
const sql = `SELECT "id", 'foo' AS "type" FROM "table"`;
expect(getParsedSql(sql)).to.equal(sql);
});
describe('union operator', () => {
it('should combine multiple statements', () => {
expect(getParsedSql(`select 1 union select '1' union select a from t union (select true)`))
.to.equal(`SELECT 1 UNION SELECT '1' UNION SELECT "a" FROM "t" UNION SELECT TRUE`);
});
it('should be supported in expressions', () => {
const sql = `select * from (select 1 union select 2) t`;
expect(getParsedSql(sql)).to.equal(`SELECT * FROM (SELECT 1 UNION SELECT 2) AS "t"`);
});
});
describe('unsupported statements', () => {
const unsupportedStatements = {
insert: 'INSERT INTO t (col1, col2) VALUES (1, 2)',
update: 'UPDATE t SET col1 = 5 WHERE id = 1337'
};
Object.keys(unsupportedStatements).forEach((stmtType) => {
it(`should throw exception for ${stmtType} statements`, () => {
expect(() => {
getParsedSql(unsupportedStatements[stmtType]);
}).to.throw(Error, 'Only SELECT statements supported at the moment');
});
});
});
});