You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/select.spec.js
+15-2Lines changed: 15 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,12 @@ describe('select', () => {
211
211
expect(parser.sqlify(ast,opt)).to.eql("SELECT EXTRACT(MICROSECONDS FROM TIME '17:12:28.5')");
212
212
expect(parser.sqlify(parser.astify("SELECT EXTRACT(MILLISECONDS FROM TIMESTAMP '2016-12-31 13:30:15')",opt),opt)).to.eql("SELECT EXTRACT(MILLISECONDS FROM TIMESTAMP '2016-12-31 13:30:15')");
213
213
expect(parser.sqlify(parser.astify("SELECT EXTRACT(MILLISECONDS FROM '2016-12-31 13:30:15')",opt),opt)).to.eql("SELECT EXTRACT(MILLISECONDS FROM '2016-12-31 13:30:15')");
214
+
expect(parser.sqlify(parser.astify(`WITH tss AS
215
+
(SELECT CURRENT_TIMESTAMP AS ts)
216
+
SELECT
217
+
EXTRACT(EPOCH FROM ts)
218
+
FROM
219
+
tss`,opt),opt)).to.eql('WITH tss AS (SELECT CURRENT_TIMESTAMP AS "ts") SELECT EXTRACT(EPOCH FROM "ts") FROM "tss"');
214
220
});
215
221
216
222
it('should parse function expression',()=>{
@@ -332,6 +338,13 @@ describe('select', () => {
332
338
expect(backSQL).to.equal('SELECT `user0__`.`user_id` AS `userId` FROM `user` AS `user0__`')
333
339
})
334
340
341
+
it('should support select from db.xxx.table',()=>{
342
+
constsql='select id from db-name.public.table-name'
343
+
constopt={database: 'postgresql'}
344
+
constast=parser.astify(sql,opt)
345
+
constbackSQL=parser.sqlify(ast,opt)
346
+
expect(backSQL).to.equal('SELECT "id" FROM "db-name.public"."table-name"')
347
+
})
335
348
336
349
it('should parse subselect',()=>{
337
350
constast=parser.astify('SELECT * FROM (SELECT id FROM t1) someAlias');
@@ -1012,9 +1025,9 @@ describe('select', () => {
1012
1025
expect(fun).to.throw(`authority = 'select::null::b' is required in table whiteList to execute SQL = '${sql}'`)
1013
1026
})
1014
1027
it('should fail for as column reserved word check',()=>{
1015
-
constsql='SELECT id as type FROM b'
1028
+
constsql='SELECT id as delete FROM b'
1016
1029
constfun=parser.astify.bind(parser,sql)
1017
-
expect(fun).to.throw('Error: "type" is a reserved word, can not as alias clause')
1030
+
expect(fun).to.throw('Error: "delete" is a reserved word, can not as alias clause')
1018
1031
})
1019
1032
it('should fail for as table reserved word check',()=>{
0 commit comments