workers-qb 1.9.0 → 1.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -48
- package/dist/index.d.mts +21 -13
- package/dist/index.d.ts +21 -13
- package/dist/index.js +18 -4
- package/dist/index.mjs +18 -4
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,44 +1,74 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://workers-qb.massadas.com/">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/G4brym/workers-qb/refs/heads/main/docs/assets/logo.png" width="500" height="auto" alt="workers-qb"/>
|
|
4
|
+
</a>
|
|
5
|
+
</div>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
<em>Zero-dependency Query Builder for Cloudflare Workers</em>
|
|
9
|
+
</p>
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://workers-qb.massadas.com/" target="_blank">
|
|
13
|
+
<img src="https://img.shields.io/badge/docs-workers--qb-blue.svg" alt="Documentation">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/workers-qb" target="_blank">
|
|
16
|
+
<img src="https://img.shields.io/npm/v/workers-qb.svg" alt="npm version">
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://github.com/G4brym/workers-qb/blob/main/LICENSE" target="_blank">
|
|
19
|
+
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="Software License">
|
|
20
|
+
</a>
|
|
21
|
+
</p>
|
|
6
22
|
|
|
7
|
-
|
|
8
|
-
traditional ORM.
|
|
23
|
+
## Overview
|
|
9
24
|
|
|
10
|
-
|
|
11
|
-
from code for direct SQL access using convenient wrapper methods.
|
|
25
|
+
workers-qb is a lightweight query builder designed specifically for Cloudflare Workers. It provides a simple, standardized interface while maintaining the performance benefits of raw queries over traditional ORMs.
|
|
12
26
|
|
|
13
|
-
|
|
27
|
+
📚 [Read the full documentation](https://workers-qb.massadas.com/)
|
|
14
28
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
29
|
+
### Key Differences from ORMs
|
|
30
|
+
|
|
31
|
+
- Focused on direct SQL access with convenient wrapper methods
|
|
32
|
+
- Maintains raw query performance
|
|
33
|
+
- Zero dependencies
|
|
34
|
+
- Lightweight and Worker-optimized
|
|
35
|
+
|
|
36
|
+
## Supported Databases
|
|
37
|
+
|
|
38
|
+
- ☁️ [Cloudflare D1](https://workers-qb.massadas.com/databases/cloudflare-d1/)
|
|
39
|
+
- 💾 [Cloudflare Durable Objects](https://workers-qb.massadas.com/databases/cloudflare-do/)
|
|
40
|
+
- 🐘 [PostgreSQL (via node-postgres)](https://workers-qb.massadas.com/databases/postgresql/)
|
|
41
|
+
- 🔌 [Bring Your Own Database](https://workers-qb.massadas.com/databases/bring-your-own-database/)
|
|
19
42
|
|
|
20
43
|
## Features
|
|
21
44
|
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
45
|
+
### Core Features
|
|
46
|
+
- Zero dependencies
|
|
47
|
+
- Full TypeScript support
|
|
48
|
+
- Database schema migrations
|
|
49
|
+
- Type checking for data reads
|
|
50
|
+
- Lazy row loading
|
|
51
|
+
|
|
52
|
+
### Query Operations
|
|
53
|
+
- Table operations (create/drop)
|
|
54
|
+
- CRUD operations (insert/update/select/delete)
|
|
55
|
+
- Bulk inserts
|
|
56
|
+
- JOIN queries
|
|
57
|
+
- Modular SELECT queries
|
|
58
|
+
- ON CONFLICT handling
|
|
59
|
+
- UPSERT support
|
|
32
60
|
|
|
33
61
|
## Installation
|
|
34
62
|
|
|
35
|
-
```
|
|
63
|
+
```bash
|
|
36
64
|
npm install workers-qb --save
|
|
37
65
|
```
|
|
38
66
|
|
|
39
|
-
##
|
|
67
|
+
## Usage Examples
|
|
68
|
+
|
|
69
|
+
### Cloudflare D1
|
|
40
70
|
|
|
41
|
-
```
|
|
71
|
+
```typescript
|
|
42
72
|
import { D1QB } from 'workers-qb'
|
|
43
73
|
|
|
44
74
|
export interface Env {
|
|
@@ -55,7 +85,7 @@ export default {
|
|
|
55
85
|
level: number
|
|
56
86
|
}
|
|
57
87
|
|
|
58
|
-
//
|
|
88
|
+
// Using object syntax
|
|
59
89
|
const employeeList = await qb
|
|
60
90
|
.fetchAll<Employee>({
|
|
61
91
|
tableName: 'employees',
|
|
@@ -66,11 +96,11 @@ export default {
|
|
|
66
96
|
})
|
|
67
97
|
.execute()
|
|
68
98
|
|
|
69
|
-
//
|
|
70
|
-
const employeeListModular = await qb
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
99
|
+
// Using method chaining
|
|
100
|
+
const employeeListModular = await qb
|
|
101
|
+
.select<Employee>('employees')
|
|
102
|
+
.where('active = ?', true)
|
|
103
|
+
.execute()
|
|
74
104
|
|
|
75
105
|
return Response.json({
|
|
76
106
|
activeEmployees: employeeList.results?.length || 0,
|
|
@@ -79,41 +109,39 @@ export default {
|
|
|
79
109
|
}
|
|
80
110
|
```
|
|
81
111
|
|
|
82
|
-
|
|
112
|
+
### Cloudflare Durable Objects
|
|
83
113
|
|
|
84
|
-
```
|
|
114
|
+
```typescript
|
|
85
115
|
import { DOQB } from 'workers-qb'
|
|
86
116
|
|
|
87
117
|
export class DOSRS extends DurableObject {
|
|
88
118
|
getEmployees() {
|
|
89
119
|
const qb = new DOQB(this.ctx.storage.sql)
|
|
90
|
-
|
|
91
|
-
|
|
120
|
+
|
|
121
|
+
return qb
|
|
92
122
|
.fetchAll({
|
|
93
123
|
tableName: 'employees',
|
|
94
124
|
})
|
|
95
125
|
.execute()
|
|
96
|
-
|
|
97
|
-
return fetched.results
|
|
126
|
+
.results
|
|
98
127
|
}
|
|
99
128
|
}
|
|
100
129
|
```
|
|
101
130
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
Remember to close the connection using `ctx.waitUntil(qb.close());` or `await qb.close();` at the end of your request.
|
|
105
|
-
You may also reuse this connection to execute multiple queries, or share it between multiple requests if you are using
|
|
106
|
-
a connection pool in front of your PostgreSQL.
|
|
107
|
-
|
|
108
|
-
You must also enable `node_compat = true` in your `wrangler.toml`
|
|
109
|
-
|
|
110
|
-
You need to install `node-postgres`:
|
|
131
|
+
### PostgreSQL Integration
|
|
111
132
|
|
|
133
|
+
First, install the required PostgreSQL client:
|
|
112
134
|
```bash
|
|
113
135
|
npm install pg --save
|
|
114
136
|
```
|
|
115
137
|
|
|
116
|
-
|
|
138
|
+
Enable Node compatibility in `wrangler.toml`:
|
|
139
|
+
```toml
|
|
140
|
+
node_compat = true
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Example usage:
|
|
144
|
+
```typescript
|
|
117
145
|
import { PGQB } from 'workers-qb'
|
|
118
146
|
import { Client } from 'pg'
|
|
119
147
|
|
|
@@ -126,7 +154,6 @@ export default {
|
|
|
126
154
|
const qb = new PGQB(new Client(env.DB_URL))
|
|
127
155
|
await qb.connect()
|
|
128
156
|
|
|
129
|
-
// Generated query: SELECT count(*) as count FROM employees WHERE active = ?1 LIMIT 1
|
|
130
157
|
const fetched = await qb
|
|
131
158
|
.fetchOne({
|
|
132
159
|
tableName: 'employees',
|
|
@@ -138,10 +165,30 @@ export default {
|
|
|
138
165
|
})
|
|
139
166
|
.execute()
|
|
140
167
|
|
|
168
|
+
// Important: Close the connection
|
|
141
169
|
ctx.waitUntil(qb.close())
|
|
170
|
+
|
|
142
171
|
return Response.json({
|
|
143
172
|
activeEmployees: fetched.results?.count || 0,
|
|
144
173
|
})
|
|
145
174
|
},
|
|
146
175
|
}
|
|
147
176
|
```
|
|
177
|
+
|
|
178
|
+
## Documentation
|
|
179
|
+
|
|
180
|
+
Visit our [comprehensive documentation](https://workers-qb.massadas.com/) for detailed information about:
|
|
181
|
+
|
|
182
|
+
- [Basic Queries](https://workers-qb.massadas.com/basic-queries/)
|
|
183
|
+
- [Advanced Queries](https://workers-qb.massadas.com/advanced-queries/)
|
|
184
|
+
- [Migrations](https://workers-qb.massadas.com/migrations/)
|
|
185
|
+
- [Type Checking](https://workers-qb.massadas.com/type-check/)
|
|
186
|
+
- [Database-specific guides](https://workers-qb.massadas.com/databases/d1)
|
|
187
|
+
|
|
188
|
+
## Contributing
|
|
189
|
+
|
|
190
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/index.d.mts
CHANGED
|
@@ -95,9 +95,9 @@ type RawQueryFetchAll = Omit<RawQuery, 'fetchType'> & {
|
|
|
95
95
|
fetchType: FetchTypes.ALL;
|
|
96
96
|
};
|
|
97
97
|
type RawQueryWithoutFetching = Omit<RawQuery, 'fetchType'>;
|
|
98
|
-
type SelectAll
|
|
98
|
+
type SelectAll = SelectOne & {
|
|
99
99
|
limit?: number;
|
|
100
|
-
lazy?:
|
|
100
|
+
lazy?: boolean;
|
|
101
101
|
};
|
|
102
102
|
type ConflictUpsert = {
|
|
103
103
|
column: string | Array<string>;
|
|
@@ -166,17 +166,17 @@ type PGResult = {
|
|
|
166
166
|
lastRowId?: string | number;
|
|
167
167
|
rowCount: number;
|
|
168
168
|
};
|
|
169
|
-
type IterableResult<ResultWrapper, Result, IsAsync extends boolean
|
|
169
|
+
type IterableResult<ResultWrapper, Result, IsAsync extends boolean> = IsAsync extends true ? Promise<Merge<ResultWrapper, {
|
|
170
170
|
results?: AsyncIterable<Result>;
|
|
171
171
|
}>> : Merge<ResultWrapper, {
|
|
172
172
|
results?: Iterable<Result>;
|
|
173
|
-
}
|
|
174
|
-
type FullArrayResult<ResultWrapper, Result, IsAsync extends boolean
|
|
173
|
+
}>;
|
|
174
|
+
type FullArrayResult<ResultWrapper, Result, IsAsync extends boolean> = IsAsync extends true ? Promise<Merge<ResultWrapper, {
|
|
175
175
|
results?: Array<Result>;
|
|
176
176
|
}>> : Merge<ResultWrapper, {
|
|
177
177
|
results?: Array<Result>;
|
|
178
|
-
}
|
|
179
|
-
type ArrayResult<ResultWrapper, Result, IsAsync extends boolean, IsLazy extends
|
|
178
|
+
}>;
|
|
179
|
+
type ArrayResult<ResultWrapper, Result, IsAsync extends boolean, IsLazy extends boolean = false> = IsLazy extends true ? IterableResult<ResultWrapper, Result, IsAsync> : FullArrayResult<ResultWrapper, Result, IsAsync>;
|
|
180
180
|
type OneResult<ResultWrapper, Result> = Merge<ResultWrapper, {
|
|
181
181
|
results?: Result;
|
|
182
182
|
}>;
|
|
@@ -191,8 +191,8 @@ declare function defaultLogger(query: RawQuery, meta: QueryLoggerMeta): any;
|
|
|
191
191
|
declare function asyncLoggerWrapper<Async extends boolean = true>(query: Query<any, Async> | Query<any, Async>[], loggerFunction: CallableFunction | undefined, innerFunction: () => any): Promise<any>;
|
|
192
192
|
declare function syncLoggerWrapper<Async extends boolean = false>(query: Query<any, Async> | Query<any, Async>[], loggerFunction: CallableFunction | undefined, innerFunction: () => any): any;
|
|
193
193
|
|
|
194
|
-
interface SelectExecuteOptions
|
|
195
|
-
lazy?:
|
|
194
|
+
interface SelectExecuteOptions {
|
|
195
|
+
lazy?: boolean;
|
|
196
196
|
}
|
|
197
197
|
declare class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnObject, IsAsync extends boolean = true> {
|
|
198
198
|
_debugger: boolean;
|
|
@@ -212,10 +212,16 @@ declare class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnO
|
|
|
212
212
|
offset(offset: SelectAll['offset']): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>;
|
|
213
213
|
limit(limit: SelectAll['limit']): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>;
|
|
214
214
|
_parseArray(fieldName: string, option: any, value: any): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>;
|
|
215
|
-
getQueryAll<
|
|
215
|
+
getQueryAll<P extends SelectExecuteOptions = SelectExecuteOptions>(options?: P): Query<ArrayResult<GenericResultWrapper, GenericResult, IsAsync, P extends {
|
|
216
|
+
lazy: true;
|
|
217
|
+
} ? true : false>, IsAsync>;
|
|
216
218
|
getQueryOne(): Query<OneResult<GenericResultWrapper, GenericResult>, IsAsync>;
|
|
217
|
-
execute<
|
|
218
|
-
|
|
219
|
+
execute<P extends SelectExecuteOptions = SelectExecuteOptions>(options?: P): ArrayResult<GenericResultWrapper, GenericResult, IsAsync, P extends {
|
|
220
|
+
lazy: true;
|
|
221
|
+
} ? true : false>;
|
|
222
|
+
all<P extends SelectExecuteOptions = SelectExecuteOptions>(options?: P): ArrayResult<GenericResultWrapper, GenericResult, IsAsync, P extends {
|
|
223
|
+
lazy: true;
|
|
224
|
+
} ? true : false>;
|
|
219
225
|
one(): MaybeAsync<IsAsync, OneResult<GenericResultWrapper, GenericResult>>;
|
|
220
226
|
count(): MaybeAsync<IsAsync, CountResult<GenericResultWrapper>>;
|
|
221
227
|
}
|
|
@@ -239,7 +245,9 @@ declare class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
|
|
|
239
245
|
}): Query<ArrayResult<GenericResultWrapper, GenericResult, IsAsync>, IsAsync>;
|
|
240
246
|
select<GenericResult = DefaultReturnObject>(tableName: string): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>;
|
|
241
247
|
fetchOne<GenericResult = DefaultReturnObject>(params: SelectOne): QueryWithExtra<GenericResultWrapper, OneResult<GenericResultWrapper, GenericResult>, IsAsync>;
|
|
242
|
-
fetchAll<GenericResult = DefaultReturnObject,
|
|
248
|
+
fetchAll<GenericResult = DefaultReturnObject, P extends SelectAll = SelectAll>(params: P): QueryWithExtra<GenericResultWrapper, ArrayResult<GenericResultWrapper, GenericResult, IsAsync, P extends {
|
|
249
|
+
lazy: true;
|
|
250
|
+
} ? true : false>, IsAsync>;
|
|
243
251
|
raw<GenericResult = DefaultReturnObject>(params: RawQueryFetchOne): Query<OneResult<GenericResultWrapper, GenericResult>, IsAsync>;
|
|
244
252
|
raw<GenericResult = DefaultReturnObject>(params: RawQueryFetchAll): Query<ArrayResult<GenericResultWrapper, GenericResult, IsAsync>, IsAsync>;
|
|
245
253
|
raw<GenericResult = DefaultReturnObject>(params: RawQueryWithoutFetching): Query<GenericResultWrapper, IsAsync>;
|
package/dist/index.d.ts
CHANGED
|
@@ -95,9 +95,9 @@ type RawQueryFetchAll = Omit<RawQuery, 'fetchType'> & {
|
|
|
95
95
|
fetchType: FetchTypes.ALL;
|
|
96
96
|
};
|
|
97
97
|
type RawQueryWithoutFetching = Omit<RawQuery, 'fetchType'>;
|
|
98
|
-
type SelectAll
|
|
98
|
+
type SelectAll = SelectOne & {
|
|
99
99
|
limit?: number;
|
|
100
|
-
lazy?:
|
|
100
|
+
lazy?: boolean;
|
|
101
101
|
};
|
|
102
102
|
type ConflictUpsert = {
|
|
103
103
|
column: string | Array<string>;
|
|
@@ -166,17 +166,17 @@ type PGResult = {
|
|
|
166
166
|
lastRowId?: string | number;
|
|
167
167
|
rowCount: number;
|
|
168
168
|
};
|
|
169
|
-
type IterableResult<ResultWrapper, Result, IsAsync extends boolean
|
|
169
|
+
type IterableResult<ResultWrapper, Result, IsAsync extends boolean> = IsAsync extends true ? Promise<Merge<ResultWrapper, {
|
|
170
170
|
results?: AsyncIterable<Result>;
|
|
171
171
|
}>> : Merge<ResultWrapper, {
|
|
172
172
|
results?: Iterable<Result>;
|
|
173
|
-
}
|
|
174
|
-
type FullArrayResult<ResultWrapper, Result, IsAsync extends boolean
|
|
173
|
+
}>;
|
|
174
|
+
type FullArrayResult<ResultWrapper, Result, IsAsync extends boolean> = IsAsync extends true ? Promise<Merge<ResultWrapper, {
|
|
175
175
|
results?: Array<Result>;
|
|
176
176
|
}>> : Merge<ResultWrapper, {
|
|
177
177
|
results?: Array<Result>;
|
|
178
|
-
}
|
|
179
|
-
type ArrayResult<ResultWrapper, Result, IsAsync extends boolean, IsLazy extends
|
|
178
|
+
}>;
|
|
179
|
+
type ArrayResult<ResultWrapper, Result, IsAsync extends boolean, IsLazy extends boolean = false> = IsLazy extends true ? IterableResult<ResultWrapper, Result, IsAsync> : FullArrayResult<ResultWrapper, Result, IsAsync>;
|
|
180
180
|
type OneResult<ResultWrapper, Result> = Merge<ResultWrapper, {
|
|
181
181
|
results?: Result;
|
|
182
182
|
}>;
|
|
@@ -191,8 +191,8 @@ declare function defaultLogger(query: RawQuery, meta: QueryLoggerMeta): any;
|
|
|
191
191
|
declare function asyncLoggerWrapper<Async extends boolean = true>(query: Query<any, Async> | Query<any, Async>[], loggerFunction: CallableFunction | undefined, innerFunction: () => any): Promise<any>;
|
|
192
192
|
declare function syncLoggerWrapper<Async extends boolean = false>(query: Query<any, Async> | Query<any, Async>[], loggerFunction: CallableFunction | undefined, innerFunction: () => any): any;
|
|
193
193
|
|
|
194
|
-
interface SelectExecuteOptions
|
|
195
|
-
lazy?:
|
|
194
|
+
interface SelectExecuteOptions {
|
|
195
|
+
lazy?: boolean;
|
|
196
196
|
}
|
|
197
197
|
declare class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnObject, IsAsync extends boolean = true> {
|
|
198
198
|
_debugger: boolean;
|
|
@@ -212,10 +212,16 @@ declare class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnO
|
|
|
212
212
|
offset(offset: SelectAll['offset']): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>;
|
|
213
213
|
limit(limit: SelectAll['limit']): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>;
|
|
214
214
|
_parseArray(fieldName: string, option: any, value: any): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>;
|
|
215
|
-
getQueryAll<
|
|
215
|
+
getQueryAll<P extends SelectExecuteOptions = SelectExecuteOptions>(options?: P): Query<ArrayResult<GenericResultWrapper, GenericResult, IsAsync, P extends {
|
|
216
|
+
lazy: true;
|
|
217
|
+
} ? true : false>, IsAsync>;
|
|
216
218
|
getQueryOne(): Query<OneResult<GenericResultWrapper, GenericResult>, IsAsync>;
|
|
217
|
-
execute<
|
|
218
|
-
|
|
219
|
+
execute<P extends SelectExecuteOptions = SelectExecuteOptions>(options?: P): ArrayResult<GenericResultWrapper, GenericResult, IsAsync, P extends {
|
|
220
|
+
lazy: true;
|
|
221
|
+
} ? true : false>;
|
|
222
|
+
all<P extends SelectExecuteOptions = SelectExecuteOptions>(options?: P): ArrayResult<GenericResultWrapper, GenericResult, IsAsync, P extends {
|
|
223
|
+
lazy: true;
|
|
224
|
+
} ? true : false>;
|
|
219
225
|
one(): MaybeAsync<IsAsync, OneResult<GenericResultWrapper, GenericResult>>;
|
|
220
226
|
count(): MaybeAsync<IsAsync, CountResult<GenericResultWrapper>>;
|
|
221
227
|
}
|
|
@@ -239,7 +245,9 @@ declare class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
|
|
|
239
245
|
}): Query<ArrayResult<GenericResultWrapper, GenericResult, IsAsync>, IsAsync>;
|
|
240
246
|
select<GenericResult = DefaultReturnObject>(tableName: string): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync>;
|
|
241
247
|
fetchOne<GenericResult = DefaultReturnObject>(params: SelectOne): QueryWithExtra<GenericResultWrapper, OneResult<GenericResultWrapper, GenericResult>, IsAsync>;
|
|
242
|
-
fetchAll<GenericResult = DefaultReturnObject,
|
|
248
|
+
fetchAll<GenericResult = DefaultReturnObject, P extends SelectAll = SelectAll>(params: P): QueryWithExtra<GenericResultWrapper, ArrayResult<GenericResultWrapper, GenericResult, IsAsync, P extends {
|
|
249
|
+
lazy: true;
|
|
250
|
+
} ? true : false>, IsAsync>;
|
|
243
251
|
raw<GenericResult = DefaultReturnObject>(params: RawQueryFetchOne): Query<OneResult<GenericResultWrapper, GenericResult>, IsAsync>;
|
|
244
252
|
raw<GenericResult = DefaultReturnObject>(params: RawQueryFetchAll): Query<ArrayResult<GenericResultWrapper, GenericResult, IsAsync>, IsAsync>;
|
|
245
253
|
raw<GenericResult = DefaultReturnObject>(params: RawQueryWithoutFetching): Query<GenericResultWrapper, IsAsync>;
|
package/dist/index.js
CHANGED
|
@@ -258,16 +258,25 @@ var SelectBuilder = class _SelectBuilder {
|
|
|
258
258
|
);
|
|
259
259
|
}
|
|
260
260
|
getQueryAll(options) {
|
|
261
|
-
return this._fetchAll(
|
|
261
|
+
return this._fetchAll({
|
|
262
|
+
...this._options,
|
|
263
|
+
...options
|
|
264
|
+
});
|
|
262
265
|
}
|
|
263
266
|
getQueryOne() {
|
|
264
267
|
return this._fetchOne(this._options);
|
|
265
268
|
}
|
|
266
269
|
execute(options) {
|
|
267
|
-
return this._fetchAll(
|
|
270
|
+
return this._fetchAll({
|
|
271
|
+
...this._options,
|
|
272
|
+
...options
|
|
273
|
+
}).execute();
|
|
268
274
|
}
|
|
269
275
|
all(options) {
|
|
270
|
-
return this._fetchAll(
|
|
276
|
+
return this._fetchAll({
|
|
277
|
+
...this._options,
|
|
278
|
+
...options
|
|
279
|
+
}).execute();
|
|
271
280
|
}
|
|
272
281
|
one() {
|
|
273
282
|
return this._fetchOne(this._options).execute();
|
|
@@ -546,6 +555,11 @@ var QueryBuilder = class {
|
|
|
546
555
|
}
|
|
547
556
|
_update(params) {
|
|
548
557
|
const whereParamsLength = typeof params.where === "object" && !Array.isArray(params.where) && params.where?.params ? Array.isArray(params.where?.params) ? Object.keys(params.where?.params).length : 1 : 0;
|
|
558
|
+
let whereString = this._where(params.where);
|
|
559
|
+
let parameterIndex = 1;
|
|
560
|
+
if (whereString && whereString.match(/(?<!\d)\?(?!\d)/)) {
|
|
561
|
+
whereString = whereString.replace(/\?/g, () => `?${parameterIndex++}`);
|
|
562
|
+
}
|
|
549
563
|
const set = [];
|
|
550
564
|
let index = 1;
|
|
551
565
|
for (const [key, value] of Object.entries(params.data)) {
|
|
@@ -557,7 +571,7 @@ var QueryBuilder = class {
|
|
|
557
571
|
}
|
|
558
572
|
}
|
|
559
573
|
return `UPDATE ${this._onConflict(params.onConflict)}${params.tableName}
|
|
560
|
-
SET ${set.join(", ")}` +
|
|
574
|
+
SET ${set.join(", ")}` + whereString + this._returning(params.returning);
|
|
561
575
|
}
|
|
562
576
|
_delete(params) {
|
|
563
577
|
return `DELETE
|
package/dist/index.mjs
CHANGED
|
@@ -216,16 +216,25 @@ var SelectBuilder = class _SelectBuilder {
|
|
|
216
216
|
);
|
|
217
217
|
}
|
|
218
218
|
getQueryAll(options) {
|
|
219
|
-
return this._fetchAll(
|
|
219
|
+
return this._fetchAll({
|
|
220
|
+
...this._options,
|
|
221
|
+
...options
|
|
222
|
+
});
|
|
220
223
|
}
|
|
221
224
|
getQueryOne() {
|
|
222
225
|
return this._fetchOne(this._options);
|
|
223
226
|
}
|
|
224
227
|
execute(options) {
|
|
225
|
-
return this._fetchAll(
|
|
228
|
+
return this._fetchAll({
|
|
229
|
+
...this._options,
|
|
230
|
+
...options
|
|
231
|
+
}).execute();
|
|
226
232
|
}
|
|
227
233
|
all(options) {
|
|
228
|
-
return this._fetchAll(
|
|
234
|
+
return this._fetchAll({
|
|
235
|
+
...this._options,
|
|
236
|
+
...options
|
|
237
|
+
}).execute();
|
|
229
238
|
}
|
|
230
239
|
one() {
|
|
231
240
|
return this._fetchOne(this._options).execute();
|
|
@@ -504,6 +513,11 @@ var QueryBuilder = class {
|
|
|
504
513
|
}
|
|
505
514
|
_update(params) {
|
|
506
515
|
const whereParamsLength = typeof params.where === "object" && !Array.isArray(params.where) && params.where?.params ? Array.isArray(params.where?.params) ? Object.keys(params.where?.params).length : 1 : 0;
|
|
516
|
+
let whereString = this._where(params.where);
|
|
517
|
+
let parameterIndex = 1;
|
|
518
|
+
if (whereString && whereString.match(/(?<!\d)\?(?!\d)/)) {
|
|
519
|
+
whereString = whereString.replace(/\?/g, () => `?${parameterIndex++}`);
|
|
520
|
+
}
|
|
507
521
|
const set = [];
|
|
508
522
|
let index = 1;
|
|
509
523
|
for (const [key, value] of Object.entries(params.data)) {
|
|
@@ -515,7 +529,7 @@ var QueryBuilder = class {
|
|
|
515
529
|
}
|
|
516
530
|
}
|
|
517
531
|
return `UPDATE ${this._onConflict(params.onConflict)}${params.tableName}
|
|
518
|
-
SET ${set.join(", ")}` +
|
|
532
|
+
SET ${set.join(", ")}` + whereString + this._returning(params.returning);
|
|
519
533
|
}
|
|
520
534
|
_delete(params) {
|
|
521
535
|
return `DELETE
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workers-qb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "Zero dependencies Query Builder for Cloudflare Workers",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
15
15
|
"lint": "npx @biomejs/biome check src/ tests/ || (npx @biomejs/biome check --write src/ tests/; exit 1)",
|
|
16
16
|
"test": "vitest run --root tests",
|
|
17
|
-
"prepare": "husky"
|
|
17
|
+
"prepare": "husky",
|
|
18
|
+
"build-docs": "npm run docs:build && cp docs/_redirects docs/.vitepress/dist/_redirects",
|
|
19
|
+
"docs:dev": "vitepress dev docs",
|
|
20
|
+
"docs:build": "vitepress build docs",
|
|
21
|
+
"docs:preview": "vitepress preview docs"
|
|
18
22
|
},
|
|
19
23
|
"publishConfig": {
|
|
20
24
|
"access": "public"
|
|
@@ -62,6 +66,7 @@
|
|
|
62
66
|
"husky": "^9.1.6",
|
|
63
67
|
"tsup": "^8.3.5",
|
|
64
68
|
"typescript": "^5.6.3",
|
|
69
|
+
"vitepress": "^1.6.3",
|
|
65
70
|
"vitest": "2.1.8",
|
|
66
71
|
"wrangler": "^3.86.0"
|
|
67
72
|
}
|