Skip to content

Commit efe6dc5

Browse files
author
oger000
committed
implement alias for sql-functions
1 parent a4dcf63 commit efe6dc5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/stringify.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ Sql.prototype.travelXORExpression = function (ast) {
161161
this.appendKeyword(ast.operator);
162162
this.travel(ast.right);
163163
}
164-
Sql.prototype.travelNull =
165-
Sql.prototype.travelBoolean =
164+
Sql.prototype.travelNull =
165+
Sql.prototype.travelBoolean =
166166
Sql.prototype.travelBooleanExtra = function (ast) {
167167
this.appendKeyword(ast.value);
168168
}
@@ -184,6 +184,12 @@ Sql.prototype.travelFunctionCall = function (ast) {
184184
}
185185
}
186186
this.append(')', true);
187+
if (ast.alias) {
188+
if (ast.hasAs) {
189+
this.appendKeyword('as');
190+
}
191+
this.travel(ast.alias);
192+
}
187193
}
188194
Sql.prototype.travelFunctionCallParam = function (ast) {
189195
if (ast.distinctOpt) {

test/main.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,10 @@ AND (rd.rd_numberofrooms <= (select sum(rn.reservation_numberofrooms) as count_r
136136
it ('restore semicolon.', function () {
137137
testParser('select a from b limit 2;');
138138
});
139+
140+
it ('recognoce alias for sql-function calls in stringify function.', function () {
141+
testParser('SELECT COUNT(*) AS total FROM b');
142+
});
143+
139144
});
140145

0 commit comments

Comments
 (0)