forked from alsotang/sql.pegjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.test.js
More file actions
81 lines (74 loc) · 2.17 KB
/
parser.test.js
File metadata and controls
81 lines (74 loc) · 2.17 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var should = require('should');
var parser = require('../');
describe('parser.test.js', function () {
it('should parse `SELECT`', function () {
var sql = 'SELECT * FROM users;';
parser.parse(sql)
.should.eql([{"stmt":"select","select_cores":[{"results":[{"column":"*"}],"from":[{"table":"users"}]}]}]);
var sql = 'SELECT a.x AS foo, b.y, x.*, * FROM a.x, b.a, d.p, d1.a1 AS b1;';
parser.parse(sql)
.should.eql([
{
"stmt": "select",
"select_cores": [
{
"results": [
{
"table": "a",
"column": "x",
"alias": "foo"
},
{
"table": "b",
"column": "y"
},
{
"table": "x",
"column": "*"
},
{
"column": "*"
}
],
"from": [
{
"database": "a",
"table": "x"
},
{
"join_constraint": null,
"database": "b",
"table": "a",
"join_op": "JOIN"
},
{
"join_constraint": null,
"database": "d",
"table": "p",
"join_op": "JOIN"
},
{
"join_constraint": null,
"database": "d1",
"table": "a1",
"alias": "b1",
"join_op": "JOIN"
}
]
}
]
}
]);
});
// it('should parse `ORDER BY`', function () {
// var sql = 'SELECT table1.field1 FROM table1 ORDER BY table1.field1;';
// console.log('%j', parser.parse(sql));
// parser.parse(sql)
// .should.eql([]);
// });
it('should be case-insensitive', function () {
var sql = 'sElEcT * FroM users;';
parser.parse(sql)
.should.eql([{"stmt":"select","select_cores":[{"results":[{"column":"*"}],"from":[{"table":"users"}]}]}]);
});
});