Skip to content

Commit

Permalink
Merge pull request #1181 from a0viedo/alias-fix
Browse files Browse the repository at this point in the history
fixes bug when using dot in as identifier
  • Loading branch information
elhigu committed Feb 3, 2016
2 parents 4b13449 + a1e6dbb commit 538cdee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ assign(Formatter.prototype, {
return this._wrapString(value + '');
},

wrapAsIdentifier: function wrapAsIdentifier(value) {
return this.client.wrapIdentifier((value || '').trim());
},

alias: function(first, second) {
return first + ' as ' + second;
},
Expand Down Expand Up @@ -141,7 +145,7 @@ assign(Formatter.prototype, {
if (asIndex !== -1) {
var first = value.slice(0, asIndex)
var second = value.slice(asIndex + 4)
return this.alias(this.wrap(first), this.wrap(second))
return this.alias(this.wrap(first), this.wrapAsIdentifier(second))
}
var i = -1, wrapped = [];
segments = value.split('.');
Expand Down
9 changes: 9 additions & 0 deletions test/unit/query/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ describe("QueryBuilder", function() {
});
});

it("allows alias with dots in the identifier name", function() {
testsql(qb().select('foo as bar.baz').from('users'), {
mysql: 'select `foo` as `bar.baz` from `users`',
oracle: 'select "foo" "bar.baz" from "users"',
mssql: 'select [foo] as [bar.baz] from [users]',
default: 'select "foo" as "bar.baz" from "users"'
});
});

it("basic table wrapping", function() {
testsql(qb().select('*').from('public.users'), {
mysql: 'select * from `public`.`users`',
Expand Down

0 comments on commit 538cdee

Please sign in to comment.