Skip to content

Commit

Permalink
fix: SelectBuilder should query all columns if none explicitly selected
Browse files Browse the repository at this point in the history
  • Loading branch information
langpavel committed Nov 20, 2018
1 parent c6f5cfd commit 411af95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pg-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class SelectBuilder {
createQuery() {
let sql: SqlFragment[] = [
this.command, // usually 'SELECT'
this.selection.join(', '),
this.selection.length ? this.selection.join(', ') : '*',
this.tableSource ? `FROM ${this.tableSource}` : '',
...this.joins,
];
Expand Down
8 changes: 8 additions & 0 deletions test/__snapshots__/pg-query-builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ SQL {
FROM "testTable"
} Arguments Array []
`;

exports[`SelectBuilder should query all columns if none explicitly selected 1`] = `
SQL {
SELECT
*
FROM test
} Arguments Array []
`;
5 changes: 5 additions & 0 deletions test/pg-query-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ describe('SelectBuilder', () => {
expect(query).toMatchSnapshot();
});

it('should query all columns if none explicitly selected', () => {
const query = new SelectBuilder('test');
expect(query).toMatchSnapshot();
});

it('should create simple query', () => {
const query = new SelectBuilder('"testTable"')
.select('a, b')
Expand Down

0 comments on commit 411af95

Please sign in to comment.