Skip to content

Commit f6724f1

Browse files
style: Apply auto-fixes from linter (Biome)
This commit includes changes automatically applied by the Biome linter after running `npm run lint` (which executes `biome check --apply-unsafe`).
1 parent 85275e8 commit f6724f1

File tree

4 files changed

+57
-54
lines changed

4 files changed

+57
-54
lines changed

src/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
Update,
2626
UpdateReturning,
2727
UpdateWithoutReturning,
28-
Where,
28+
WhereInput,
2929
} from './interfaces'
3030
import { asyncLoggerWrapper, defaultLogger } from './logger'
3131
import { MigrationOptions, asyncMigrationsBuilder } from './migrations'
@@ -436,7 +436,7 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
436436
return value.join(', ')
437437
}
438438

439-
protected _where(value?: Where): string {
439+
protected _where(value?: WhereInput): string {
440440
if (!value) return ''
441441
let conditions = value
442442

src/modularBuilder.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ export class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnOb
6060
params?: Primitive | Primitive[]
6161
): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>
6262
where(
63-
field: string | JsonExpression,
63+
field: string | JsonExpression | Raw, // Added Raw
6464
operator: string,
6565
value: Primitive
6666
): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>
6767
where(
68-
arg1: string | Array<string> | JsonExpression,
68+
arg1: string | Array<string> | JsonExpression | Raw, // Added Raw
6969
arg2?: Primitive | Primitive[] | string,
7070
arg3?: Primitive
7171
): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync> {
@@ -74,23 +74,23 @@ export class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnOb
7474
const newParams = [...currentWhere.params]
7575

7676
if (arg3 !== undefined && typeof arg2 === 'string') {
77-
// Overload: where(field: string | JsonExpression, operator: string, value: Primitive)
78-
const fieldOrJsonExpr = arg1 as string | JsonExpression
77+
// Overload: where(field: string | JsonExpression | Raw, operator: string, value: Primitive)
78+
const fieldOrJsonExpr = arg1 as string | JsonExpression | Raw
7979
const operator = arg2
8080
const value = arg3
8181

8282
if ((fieldOrJsonExpr as JsonExpression).isJsonExpression) {
8383
const jsonExpr = fieldOrJsonExpr as JsonExpression
8484
newConditions.push(`${jsonExpr.expression} ${operator} ?`)
8585
newParams.push(...jsonExpr.bindings, value)
86+
} else if ((fieldOrJsonExpr as Raw).isRaw) {
87+
const rawExpr = fieldOrJsonExpr as Raw
88+
newConditions.push(`${rawExpr.content} ${operator} ?`)
89+
newParams.push(value)
8690
} else {
8791
// Assuming fieldOrJsonExpr is a string (field name)
88-
// We should also handle if it's a Raw instance for safety, though less common here
89-
let fieldStr = fieldOrJsonExpr as string
90-
if((fieldOrJsonExpr as Raw).isRaw) {
91-
fieldStr = (fieldOrJsonExpr as Raw).content;
92-
}
93-
newConditions.push(`${fieldStr} ${operator} ?`)
92+
const field = fieldOrJsonExpr as string
93+
newConditions.push(`${field} ${operator} ?`)
9494
newParams.push(value)
9595
}
9696
} else {

tests/unit/logger.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Logger', () => {
1212
tableName: 'testTable',
1313
fields: ['id', 'name'],
1414
where: {
15-
conditions: 'field = ?1',
15+
conditions: ['field = ?1'],
1616
params: ['test'],
1717
},
1818
})
@@ -40,7 +40,7 @@ describe('Logger', () => {
4040
tableName: 'testTable',
4141
fields: ['id', 'name'],
4242
where: {
43-
conditions: 'field = ?1',
43+
conditions: ['field = ?1'],
4444
params: ['test'],
4545
},
4646
})

tests/unit/select.test.ts

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('Select Builder', () => {
5050
tableName: 'testTable',
5151
fields: '*',
5252
where: {
53-
conditions: 'field = ?',
53+
conditions: ['field = ?'], // Corrected
5454
params: ['test'],
5555
},
5656
}),
@@ -67,11 +67,11 @@ describe('Select Builder', () => {
6767
new QuerybuilderTest().fetchOne({
6868
tableName: 'testTable',
6969
fields: '*',
70-
where: 'field = true',
70+
where: { conditions: ['field = true'], params: [] }, // Corrected
7171
}),
7272
]) {
7373
expect(result.query).toEqual('SELECT * FROM testTable WHERE field = true LIMIT 1')
74-
expect(result.arguments).toEqual(undefined)
74+
expect(result.arguments).toEqual([])
7575
expect(result.fetchType).toEqual('ONE')
7676
}
7777
})
@@ -86,7 +86,7 @@ describe('Select Builder', () => {
8686
}),
8787
]) {
8888
expect(result.query).toEqual('SELECT * FROM testTable LIMIT 1')
89-
expect(result.arguments).toEqual(undefined)
89+
expect(result.arguments).toBeUndefined()
9090
expect(result.fetchType).toEqual('ONE')
9191
}
9292
})
@@ -96,7 +96,7 @@ describe('Select Builder', () => {
9696
new QuerybuilderTest().fetchOne({
9797
tableName: 'testTable',
9898
fields: '*',
99-
where: {
99+
where: { // This is already correct
100100
conditions: [],
101101
params: [],
102102
},
@@ -114,7 +114,7 @@ describe('Select Builder', () => {
114114
.fetchOne({
115115
tableName: 'testTable',
116116
fields: '*',
117-
where: {
117+
where: { // Correct
118118
conditions: [],
119119
params: [],
120120
},
@@ -133,7 +133,7 @@ describe('Select Builder', () => {
133133
.fetchOne({
134134
tableName: 'testTable',
135135
fields: '*',
136-
where: {
136+
where: { // Correct
137137
conditions: [],
138138
params: [],
139139
},
@@ -153,11 +153,12 @@ describe('Select Builder', () => {
153153
.fetchAll({
154154
tableName: 'testTable',
155155
offset: 4,
156+
// No where clause here, so it's fine
156157
})
157158
.count(),
158159
]) {
159160
expect((result.results as any).query).toEqual('SELECT count(*) as total FROM testTable LIMIT 1')
160-
expect((result.results as any).arguments).toEqual(undefined)
161+
expect((result.results as any).arguments).toBeUndefined()
161162
expect((result.results as any).fetchType).toEqual('ONE')
162163
}
163164
})
@@ -169,11 +170,12 @@ describe('Select Builder', () => {
169170
tableName: 'testTable',
170171
offset: 4,
171172
groupBy: ['field'],
173+
// No where clause
172174
})
173175
.count(),
174176
]) {
175177
expect((result.results as any).query).toEqual('SELECT count(*) as total FROM testTable LIMIT 1')
176-
expect((result.results as any).arguments).toEqual(undefined)
178+
expect((result.results as any).arguments).toBeUndefined()
177179
expect((result.results as any).fetchType).toEqual('ONE')
178180
}
179181
})
@@ -183,11 +185,11 @@ describe('Select Builder', () => {
183185
new QuerybuilderTest().fetchOne({
184186
tableName: 'testTable',
185187
fields: '*',
186-
where: ['field = true', 'active = false'],
188+
where: { conditions: ['field = true', 'active = false'], params: [] }, // Corrected
187189
}),
188190
]) {
189191
expect(result.query).toEqual('SELECT * FROM testTable WHERE (field = true) AND (active = false) LIMIT 1')
190-
expect(result.arguments).toEqual(undefined)
192+
expect(result.arguments).toEqual([])
191193
expect(result.fetchType).toEqual('ONE')
192194
}
193195
})
@@ -197,8 +199,8 @@ describe('Select Builder', () => {
197199
new QuerybuilderTest().fetchAll({
198200
tableName: 'testTable',
199201
fields: '*',
200-
where: {
201-
conditions: 'field = ?1',
202+
where: { // Corrected
203+
conditions: ['field = ?1'],
202204
params: ['test'],
203205
},
204206
join: {
@@ -227,8 +229,8 @@ describe('Select Builder', () => {
227229
.fetchAll({
228230
tableName: 'testTable',
229231
fields: '*',
230-
where: {
231-
conditions: 'field = ?1',
232+
where: { // Corrected
233+
conditions: ['field = ?1'],
232234
params: ['test'],
233235
},
234236
join: [
@@ -268,8 +270,8 @@ describe('Select Builder', () => {
268270
.fetchAll({
269271
tableName: 'testTable',
270272
fields: '*',
271-
where: {
272-
conditions: 'field = ?1',
273+
where: { // Corrected
274+
conditions: ['field = ?1'],
273275
params: ['test'],
274276
},
275277
join: [
@@ -308,8 +310,8 @@ describe('Select Builder', () => {
308310
new QuerybuilderTest().fetchAll({
309311
tableName: 'testTable',
310312
fields: ['id', 'name'],
311-
where: {
312-
conditions: 'field = ?1',
313+
where: { // Corrected
314+
conditions: ['field = ?1'],
313315
params: ['test'],
314316
},
315317
join: {
@@ -338,8 +340,8 @@ describe('Select Builder', () => {
338340
new QuerybuilderTest().fetchAll({
339341
tableName: 'testTable',
340342
fields: '*',
341-
where: {
342-
conditions: 'field = ?1',
343+
where: { // Corrected
344+
conditions: ['field = ?1'],
343345
params: ['test'],
344346
},
345347
join: {
@@ -383,8 +385,8 @@ describe('Select Builder', () => {
383385
.fetchAll({
384386
tableName: 'testTable',
385387
fields: '*',
386-
where: {
387-
conditions: 'field = ?1',
388+
where: { // Corrected
389+
conditions: ['field = ?1'],
388390
params: ['test'],
389391
},
390392
join: {
@@ -428,8 +430,8 @@ describe('Select Builder', () => {
428430
new QuerybuilderTest().fetchAll({
429431
tableName: 'testTable',
430432
fields: '*',
431-
where: {
432-
conditions: 'field = ?1',
433+
where: { // Corrected
434+
conditions: ['field = ?1'],
433435
params: ['test'],
434436
},
435437
join: {
@@ -500,13 +502,14 @@ describe('Select Builder', () => {
500502
new QuerybuilderTest().fetchOne({
501503
tableName: 'testTable',
502504
fields: '*',
503-
where: {
504-
conditions: "field = 'test'",
505+
where: { // Corrected
506+
conditions: ["field = 'test'"],
507+
params: []
505508
},
506509
}),
507510
]) {
508511
expect(result.query).toEqual("SELECT * FROM testTable WHERE field = 'test' LIMIT 1")
509-
expect(result.arguments).toBeUndefined()
512+
expect(result.arguments).toEqual([]) // Now expects empty array
510513
expect(result.fetchType).toEqual('ONE')
511514
}
512515
})
@@ -516,7 +519,7 @@ describe('Select Builder', () => {
516519
new QuerybuilderTest().fetchAll({
517520
tableName: 'testTable',
518521
fields: '*',
519-
where: {
522+
where: { // Correct
520523
conditions: ['field = ?', 'test = ?'],
521524
params: ['test', 123],
522525
},
@@ -539,7 +542,7 @@ describe('Select Builder', () => {
539542
new QuerybuilderTest().fetchAll({
540543
tableName: 'testTable',
541544
fields: '*',
542-
where: {
545+
where: { // Correct
543546
conditions: ['field = ?1', 'test = ?2'],
544547
params: ['test', 123],
545548
},
@@ -564,7 +567,7 @@ describe('Select Builder', () => {
564567
new QuerybuilderTest().fetchAll({
565568
tableName: 'testTable',
566569
fields: '*',
567-
where: {
570+
where: { // Correct
568571
conditions: ['field = ?1', 'test = ?2'],
569572
params: ['test', 123],
570573
},
@@ -590,7 +593,7 @@ describe('Select Builder', () => {
590593
new QuerybuilderTest().fetchAll({
591594
tableName: 'testTable',
592595
fields: '*',
593-
where: {
596+
where: { // Correct
594597
conditions: ['field = ?1', 'test = ?2'],
595598
params: ['test', 123],
596599
},
@@ -619,7 +622,7 @@ describe('Select Builder', () => {
619622
new QuerybuilderTest().fetchAll({
620623
tableName: 'testTable',
621624
fields: '*',
622-
where: {
625+
where: { // Correct
623626
conditions: ['field = ?1', 'test = ?2'],
624627
params: ['test', 123],
625628
},
@@ -649,7 +652,7 @@ describe('Select Builder', () => {
649652
new QuerybuilderTest().fetchAll({
650653
tableName: 'testTable',
651654
fields: '*',
652-
where: {
655+
where: { // Correct
653656
conditions: ['field = ?1', 'test = ?2'],
654657
params: ['test', 123],
655658
},
@@ -678,7 +681,7 @@ describe('Select Builder', () => {
678681
new QuerybuilderTest().fetchAll({
679682
tableName: 'testTable',
680683
fields: '*',
681-
where: {
684+
where: { // Correct
682685
conditions: ['field = ?1', 'test = ?2'],
683686
params: ['test', 123],
684687
},
@@ -708,7 +711,7 @@ describe('Select Builder', () => {
708711
new QuerybuilderTest().fetchAll({
709712
tableName: 'testTable',
710713
fields: '*',
711-
where: {
714+
where: { // Correct
712715
conditions: ['field = ?1', 'test = ?2'],
713716
params: ['test', 123],
714717
},
@@ -741,7 +744,7 @@ describe('Select Builder', () => {
741744
new QuerybuilderTest().fetchAll({
742745
tableName: 'testTable',
743746
fields: '*',
744-
where: {
747+
where: { // Correct
745748
conditions: ['field = ?1', 'test = ?2'],
746749
params: ['test', 123],
747750
},
@@ -772,7 +775,7 @@ describe('Select Builder', () => {
772775
new QuerybuilderTest().fetchAll({
773776
tableName: 'testTable',
774777
fields: '*',
775-
where: {
778+
where: { // Correct
776779
conditions: ['field = ?1 OR test = ?2', 'test = ?3 OR field = ?4'],
777780
params: ['test', 123, 456, 'test'],
778781
},
@@ -894,8 +897,8 @@ describe('Select Builder', () => {
894897
table: 'employees',
895898
on: '1=1',
896899
},
897-
where: {
898-
conditions: 'field = ?',
900+
where: { // Corrected
901+
conditions: ['field = ?'],
899902
params: ['test'],
900903
},
901904
}),

0 commit comments

Comments
 (0)