workers-qb 1.4.0 → 1.4.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/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +45 -0
- package/dist/index.mjs +44 -0
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SqlStorage } from '@cloudflare/workers-types/experimental';
|
|
2
|
+
|
|
1
3
|
declare enum OrderTypes {
|
|
2
4
|
ASC = "ASC",
|
|
3
5
|
DESC = "DESC"
|
|
@@ -245,4 +247,14 @@ declare class PGQB extends QueryBuilder<PGResult> {
|
|
|
245
247
|
}>;
|
|
246
248
|
}
|
|
247
249
|
|
|
248
|
-
|
|
250
|
+
declare class DurableObjectDatabaseQB extends QueryBuilder<{}> {
|
|
251
|
+
db: SqlStorage;
|
|
252
|
+
constructor(db: SqlStorage);
|
|
253
|
+
execute(query: Query): Promise<{
|
|
254
|
+
results: Record<string, string | number | ArrayBuffer | null> | undefined;
|
|
255
|
+
} | {
|
|
256
|
+
results: Record<string, string | number | ArrayBuffer | null>[];
|
|
257
|
+
}>;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { type ArrayResult, ConflictTypes, type ConflictUpsert, type D1Meta, D1QB, type D1Result, type DefaultObject, type DefaultReturnObject, type Delete, type DeleteReturning, type DeleteWithoutReturning, DurableObjectDatabaseQB, FetchTypes, type Insert, type InsertMultiple, type InsertOne, type InsertWithoutReturning, type Join, JoinTypes, type OneResult, OrderTypes, PGQB, type PGResult, type Primitive, Query, QueryBuilder, Raw, type RawQuery, type RawQueryFetchAll, type RawQueryFetchOne, type RawQueryWithoutFetching, type SelectAll, type SelectOne, type Update, type UpdateReturning, type UpdateWithoutReturning, type Where, type test };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SqlStorage } from '@cloudflare/workers-types/experimental';
|
|
2
|
+
|
|
1
3
|
declare enum OrderTypes {
|
|
2
4
|
ASC = "ASC",
|
|
3
5
|
DESC = "DESC"
|
|
@@ -245,4 +247,14 @@ declare class PGQB extends QueryBuilder<PGResult> {
|
|
|
245
247
|
}>;
|
|
246
248
|
}
|
|
247
249
|
|
|
248
|
-
|
|
250
|
+
declare class DurableObjectDatabaseQB extends QueryBuilder<{}> {
|
|
251
|
+
db: SqlStorage;
|
|
252
|
+
constructor(db: SqlStorage);
|
|
253
|
+
execute(query: Query): Promise<{
|
|
254
|
+
results: Record<string, string | number | ArrayBuffer | null> | undefined;
|
|
255
|
+
} | {
|
|
256
|
+
results: Record<string, string | number | ArrayBuffer | null>[];
|
|
257
|
+
}>;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { type ArrayResult, ConflictTypes, type ConflictUpsert, type D1Meta, D1QB, type D1Result, type DefaultObject, type DefaultReturnObject, type Delete, type DeleteReturning, type DeleteWithoutReturning, DurableObjectDatabaseQB, FetchTypes, type Insert, type InsertMultiple, type InsertOne, type InsertWithoutReturning, type Join, JoinTypes, type OneResult, OrderTypes, PGQB, type PGResult, type Primitive, Query, QueryBuilder, Raw, type RawQuery, type RawQueryFetchAll, type RawQueryFetchOne, type RawQueryWithoutFetching, type SelectAll, type SelectOne, type Update, type UpdateReturning, type UpdateWithoutReturning, type Where, type test };
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
ConflictTypes: () => ConflictTypes,
|
|
24
24
|
D1QB: () => D1QB,
|
|
25
|
+
DurableObjectDatabaseQB: () => DurableObjectDatabaseQB,
|
|
25
26
|
FetchTypes: () => FetchTypes,
|
|
26
27
|
JoinTypes: () => JoinTypes,
|
|
27
28
|
OrderTypes: () => OrderTypes,
|
|
@@ -165,6 +166,8 @@ var SelectBuilder = class _SelectBuilder {
|
|
|
165
166
|
let val = [];
|
|
166
167
|
if (!Array.isArray(value)) {
|
|
167
168
|
val.push(value);
|
|
169
|
+
} else {
|
|
170
|
+
val = value;
|
|
168
171
|
}
|
|
169
172
|
if (option && Array.isArray(option)) {
|
|
170
173
|
val = [...option, ...val];
|
|
@@ -596,10 +599,52 @@ var PGQB = class extends QueryBuilder {
|
|
|
596
599
|
};
|
|
597
600
|
}
|
|
598
601
|
};
|
|
602
|
+
|
|
603
|
+
// src/databases/do.ts
|
|
604
|
+
var DurableObjectDatabaseQB = class extends QueryBuilder {
|
|
605
|
+
db;
|
|
606
|
+
constructor(db) {
|
|
607
|
+
super();
|
|
608
|
+
this.db = db;
|
|
609
|
+
}
|
|
610
|
+
async execute(query) {
|
|
611
|
+
if (this._debugger) {
|
|
612
|
+
console.log({
|
|
613
|
+
"workers-qb": {
|
|
614
|
+
query: query.query,
|
|
615
|
+
arguments: query.arguments,
|
|
616
|
+
fetchType: query.fetchType
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
if (query.arguments) {
|
|
621
|
+
let stmt = this.db.prepare(query.query);
|
|
622
|
+
const result = stmt(...query.arguments);
|
|
623
|
+
if (query.fetchType == "ONE" /* ONE */) {
|
|
624
|
+
return {
|
|
625
|
+
results: Array.from(result)[0]
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
return {
|
|
629
|
+
results: Array.from(result)
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
const cursor = this.db.exec(query.query);
|
|
633
|
+
if (query.fetchType == "ONE" /* ONE */) {
|
|
634
|
+
return {
|
|
635
|
+
results: Array.from(cursor)[0]
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
return {
|
|
639
|
+
results: Array.from(cursor)
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
};
|
|
599
643
|
// Annotate the CommonJS export names for ESM import in node:
|
|
600
644
|
0 && (module.exports = {
|
|
601
645
|
ConflictTypes,
|
|
602
646
|
D1QB,
|
|
647
|
+
DurableObjectDatabaseQB,
|
|
603
648
|
FetchTypes,
|
|
604
649
|
JoinTypes,
|
|
605
650
|
OrderTypes,
|
package/dist/index.mjs
CHANGED
|
@@ -131,6 +131,8 @@ var SelectBuilder = class _SelectBuilder {
|
|
|
131
131
|
let val = [];
|
|
132
132
|
if (!Array.isArray(value)) {
|
|
133
133
|
val.push(value);
|
|
134
|
+
} else {
|
|
135
|
+
val = value;
|
|
134
136
|
}
|
|
135
137
|
if (option && Array.isArray(option)) {
|
|
136
138
|
val = [...option, ...val];
|
|
@@ -562,9 +564,51 @@ var PGQB = class extends QueryBuilder {
|
|
|
562
564
|
};
|
|
563
565
|
}
|
|
564
566
|
};
|
|
567
|
+
|
|
568
|
+
// src/databases/do.ts
|
|
569
|
+
var DurableObjectDatabaseQB = class extends QueryBuilder {
|
|
570
|
+
db;
|
|
571
|
+
constructor(db) {
|
|
572
|
+
super();
|
|
573
|
+
this.db = db;
|
|
574
|
+
}
|
|
575
|
+
async execute(query) {
|
|
576
|
+
if (this._debugger) {
|
|
577
|
+
console.log({
|
|
578
|
+
"workers-qb": {
|
|
579
|
+
query: query.query,
|
|
580
|
+
arguments: query.arguments,
|
|
581
|
+
fetchType: query.fetchType
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
if (query.arguments) {
|
|
586
|
+
let stmt = this.db.prepare(query.query);
|
|
587
|
+
const result = stmt(...query.arguments);
|
|
588
|
+
if (query.fetchType == "ONE" /* ONE */) {
|
|
589
|
+
return {
|
|
590
|
+
results: Array.from(result)[0]
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
results: Array.from(result)
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
const cursor = this.db.exec(query.query);
|
|
598
|
+
if (query.fetchType == "ONE" /* ONE */) {
|
|
599
|
+
return {
|
|
600
|
+
results: Array.from(cursor)[0]
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
results: Array.from(cursor)
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
};
|
|
565
608
|
export {
|
|
566
609
|
ConflictTypes,
|
|
567
610
|
D1QB,
|
|
611
|
+
DurableObjectDatabaseQB,
|
|
568
612
|
FetchTypes,
|
|
569
613
|
JoinTypes,
|
|
570
614
|
OrderTypes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workers-qb",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Zero dependencies Query Builder for Cloudflare Workers",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"url": "https://github.com/G4brym/workers-qb/issues"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
+
"@cloudflare/workers-types": "^4.20240815.0",
|
|
59
60
|
"@types/jest": "^29.5.12",
|
|
60
61
|
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
|
61
62
|
"@typescript-eslint/parser": "^4.31.1",
|