Skip to content

Commit 9af9416

Browse files
committed
Merge pull request #282 from iamcharliegoddard/fix-alias-as-column-name
Tables with "alias" as a column name error on word.replace
2 parents ea5cf41 + aa98ea9 commit 9af9416

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/dialect/postgres.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ Postgres.prototype.visitTable = function(tableNode) {
689689
txt += '.';
690690
}
691691
txt += this.quote(table.getName());
692-
if(table.alias) {
692+
if(typeof table.alias === 'string') {
693693
txt += this._aliasText + this.quote(table.alias);
694694
}
695695
return [txt];
@@ -729,7 +729,7 @@ Postgres.prototype.visitColumn = function(columnNode) {
729729
}
730730
}
731731
if(!inInsertUpdateClause && !this.visitingReturning && !this._visitingCreate && !this._visitingAlter && !columnNode.subfieldContainer) {
732-
if(table.alias) {
732+
if(typeof table.alias === 'string') {
733733
txt.push(this.quote(table.alias));
734734
} else {
735735
if(table.getSchema()) {

test/column-tests.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var sql = require(__dirname + '/../lib');
66
describe('column', function() {
77
var table = sql.define({
88
name: 'user',
9-
columns: ['id', 'created']
9+
columns: ['id', 'created', 'alias']
1010
});
1111

1212
it('can be accessed by property and array', function() {
@@ -18,6 +18,10 @@ describe('column', function() {
1818
assert.equal(table.id.toQuery().text, '"user"."id"');
1919
});
2020

21+
it('works with a column name of "alias"', function() {
22+
assert.equal(table.alias.toQuery().text, '"user"."alias"');
23+
});
24+
2125
it('respects AS rename', function() {
2226
assert.equal(table.id.as('userId').toQuery().text, '"user"."id" AS "userId"');
2327
});

0 commit comments

Comments
 (0)