Skip to content

Commit

Permalink
Fix dynamic select fields (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym authored Aug 1, 2024
1 parent 58e7323 commit ea038a5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workers-qb",
"version": "1.4.0",
"version": "1.4.1",
"description": "Zero dependencies Query Builder for Cloudflare Workers",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
2 changes: 2 additions & 0 deletions src/modularBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnOb
let val = []
if (!Array.isArray(value)) {
val.push(value)
} else {
val = value
}

if (option && Array.isArray(option)) {
Expand Down
6 changes: 3 additions & 3 deletions tests/builder/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('Select Builder', () => {
for (const result of [
new QuerybuilderTest().fetchAll({
tableName: 'testTable',
fields: '*',
fields: ['id', 'name'],
where: {
conditions: 'field = ?1',
params: ['test'],
Expand All @@ -203,13 +203,13 @@ describe('Select Builder', () => {
}),
new QuerybuilderTest()
.select('testTable')
.fields('*')
.fields(['id', 'name'])
.where('field = ?1', 'test')
.join({ type: JoinTypes.LEFT, table: 'employees', on: 'testTable.employee_id = employees.id' })
.getQuery(),
]) {
expect(trimQuery(result.query)).toEqual(
'SELECT * FROM testTable LEFT JOIN employees ON testTable.employee_id = employees.id WHERE field = ?1'
'SELECT id, name FROM testTable LEFT JOIN employees ON testTable.employee_id = employees.id WHERE field = ?1'
)
expect(result.arguments).toEqual(['test'])
expect(result.fetchType).toEqual('ALL')
Expand Down

0 comments on commit ea038a5

Please sign in to comment.