workers-qb 1.11.1 → 1.11.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 CHANGED
@@ -35,10 +35,10 @@ workers-qb is a lightweight query builder designed specifically for Cloudflare W
35
35
 
36
36
  ## Supported Databases
37
37
 
38
- - ☁️ [Cloudflare D1](https://workers-qb.massadas.com/databases/cloudflare-d1/)
39
- - 💾 [Cloudflare Durable Objects](https://workers-qb.massadas.com/databases/cloudflare-do/)
38
+ - ☁️ [Cloudflare D1](https://workers-qb.massadas.com/databases/d1/)
39
+ - 💾 [Cloudflare Durable Objects](https://workers-qb.massadas.com/databases/do/)
40
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/)
41
+ - 🔌 [Bring Your Own Database](https://workers-qb.massadas.com/databases/byodb/)
42
42
 
43
43
  ## Features
44
44
 
package/dist/index.d.mts CHANGED
@@ -344,19 +344,9 @@ declare class D1QB extends QueryBuilder<D1Result> {
344
344
  batchExecute(queryArray: Query[]): Promise<any>;
345
345
  }
346
346
 
347
- declare class PGQB extends QueryBuilder<PGResult> {
348
- db: any;
349
- _migrationsBuilder: typeof asyncMigrationsBuilder;
350
- constructor(db: any, options?: QueryBuilderOptions);
351
- migrations(options: MigrationOptions): asyncMigrationsBuilder<PGResult>;
352
- connect(): Promise<void>;
353
- close(): Promise<void>;
354
- execute(query: Query): Promise<any>;
355
- }
356
-
357
347
  interface SqlStorage {
358
348
  exec: any;
359
- prepare: any;
349
+ get databaseSize(): number;
360
350
  Cursor: any;
361
351
  Statement: any;
362
352
  }
@@ -369,4 +359,14 @@ declare class DOQB extends QueryBuilder<DOResult, false> {
369
359
  lazyExecute(query: Query<any, false>): Iterable<any>;
370
360
  }
371
361
 
362
+ declare class PGQB extends QueryBuilder<PGResult> {
363
+ db: any;
364
+ _migrationsBuilder: typeof asyncMigrationsBuilder;
365
+ constructor(db: any, options?: QueryBuilderOptions);
366
+ migrations(options: MigrationOptions): asyncMigrationsBuilder<PGResult>;
367
+ connect(): Promise<void>;
368
+ close(): Promise<void>;
369
+ execute(query: Query): Promise<any>;
370
+ }
371
+
372
372
  export { type ArrayResult, type AsyncType, ConflictTypes, type ConflictUpsert, type CountResult, type D1Meta, D1QB, type D1Result, DOQB, type DOResult, type DefaultObject, type DefaultReturnObject, type Delete, type DeleteReturning, type DeleteWithoutReturning, FetchTypes, type FullArrayResult, type Insert, type InsertMultiple, type InsertOne, type InsertWithoutReturning, type IterableResult, type Join, JoinTypes, type MaybeAsync, type Migration, type MigrationEntry, type MigrationOptions, type OneResult, OrderTypes, PGQB, type PGResult, type Primitive, Query, QueryBuilder, type QueryBuilderOptions, type QueryLoggerMeta, QueryWithExtra, Raw, type RawQuery, type RawQueryFetchAll, type RawQueryFetchOne, type RawQueryWithoutFetching, type SelectAll, type SelectOne, type SyncType, type Update, type UpdateReturning, type UpdateWithoutReturning, type Where, asyncLoggerWrapper, asyncMigrationsBuilder, defaultLogger, syncLoggerWrapper, syncMigrationsBuilder, type test, trimQuery };
package/dist/index.d.ts CHANGED
@@ -344,19 +344,9 @@ declare class D1QB extends QueryBuilder<D1Result> {
344
344
  batchExecute(queryArray: Query[]): Promise<any>;
345
345
  }
346
346
 
347
- declare class PGQB extends QueryBuilder<PGResult> {
348
- db: any;
349
- _migrationsBuilder: typeof asyncMigrationsBuilder;
350
- constructor(db: any, options?: QueryBuilderOptions);
351
- migrations(options: MigrationOptions): asyncMigrationsBuilder<PGResult>;
352
- connect(): Promise<void>;
353
- close(): Promise<void>;
354
- execute(query: Query): Promise<any>;
355
- }
356
-
357
347
  interface SqlStorage {
358
348
  exec: any;
359
- prepare: any;
349
+ get databaseSize(): number;
360
350
  Cursor: any;
361
351
  Statement: any;
362
352
  }
@@ -369,4 +359,14 @@ declare class DOQB extends QueryBuilder<DOResult, false> {
369
359
  lazyExecute(query: Query<any, false>): Iterable<any>;
370
360
  }
371
361
 
362
+ declare class PGQB extends QueryBuilder<PGResult> {
363
+ db: any;
364
+ _migrationsBuilder: typeof asyncMigrationsBuilder;
365
+ constructor(db: any, options?: QueryBuilderOptions);
366
+ migrations(options: MigrationOptions): asyncMigrationsBuilder<PGResult>;
367
+ connect(): Promise<void>;
368
+ close(): Promise<void>;
369
+ execute(query: Query): Promise<any>;
370
+ }
371
+
372
372
  export { type ArrayResult, type AsyncType, ConflictTypes, type ConflictUpsert, type CountResult, type D1Meta, D1QB, type D1Result, DOQB, type DOResult, type DefaultObject, type DefaultReturnObject, type Delete, type DeleteReturning, type DeleteWithoutReturning, FetchTypes, type FullArrayResult, type Insert, type InsertMultiple, type InsertOne, type InsertWithoutReturning, type IterableResult, type Join, JoinTypes, type MaybeAsync, type Migration, type MigrationEntry, type MigrationOptions, type OneResult, OrderTypes, PGQB, type PGResult, type Primitive, Query, QueryBuilder, type QueryBuilderOptions, type QueryLoggerMeta, QueryWithExtra, Raw, type RawQuery, type RawQueryFetchAll, type RawQueryFetchOne, type RawQueryWithoutFetching, type SelectAll, type SelectOne, type SyncType, type Update, type UpdateReturning, type UpdateWithoutReturning, type Where, asyncLoggerWrapper, asyncMigrationsBuilder, defaultLogger, syncLoggerWrapper, syncMigrationsBuilder, type test, trimQuery };
package/dist/index.js CHANGED
@@ -615,7 +615,8 @@ var QueryBuilder = class {
615
615
  }
616
616
  const columns = Object.keys(data[0]).join(", ");
617
617
  let index = 1;
618
- let orConflict = "", onConflict = "";
618
+ let orConflict = "";
619
+ let onConflict = "";
619
620
  if (params.onConflict && typeof params.onConflict === "object") {
620
621
  onConflict = this._onConflict(params.onConflict);
621
622
  if (typeof params.onConflict?.where === "object" && !Array.isArray(params.onConflict?.where) && params.onConflict?.where?.params) {
@@ -670,11 +671,12 @@ var QueryBuilder = class {
670
671
  FROM ${params.tableName}` + this._where(params.where) + this._returning(params.returning) + this._orderBy(params.orderBy) + this._limit(params.limit) + this._offset(params.offset);
671
672
  }
672
673
  _select(params, queryArgs) {
674
+ let newQueryArgs = queryArgs;
673
675
  const isTopLevelCall = queryArgs === void 0;
674
676
  if (isTopLevelCall) {
675
- queryArgs = [];
677
+ newQueryArgs = [];
676
678
  }
677
- const currentQueryArgs = queryArgs;
679
+ const currentQueryArgs = newQueryArgs;
678
680
  const context = {
679
681
  subQueryPlaceholders: params.subQueryPlaceholders,
680
682
  queryArgs: currentQueryArgs,
@@ -848,9 +850,8 @@ var QueryBuilder = class {
848
850
  objs.push(`${key} ${item}`);
849
851
  });
850
852
  return objs.join(", ");
851
- } else {
852
- return obj;
853
853
  }
854
+ return obj;
854
855
  });
855
856
  return ` ORDER BY ${result.join(", ")}`;
856
857
  }
@@ -1035,72 +1036,23 @@ var D1QB = class extends QueryBuilder {
1035
1036
  success: resp.success,
1036
1037
  results: queryArray[i]?.fetchType === "ONE" /* ONE */ ? resp.results?.[0] : resp.results
1037
1038
  };
1038
- } else {
1039
- return {
1040
- changes: resp.meta?.changes,
1041
- duration: resp.meta?.duration,
1042
- last_row_id: resp.meta?.last_row_id,
1043
- served_by: resp.meta?.served_by,
1044
- rowsRead: resp.meta?.rows_read,
1045
- rowsWritten: resp.meta?.rows_written,
1046
- meta: resp.meta,
1047
- success: resp.success
1048
- };
1049
1039
  }
1040
+ return {
1041
+ changes: resp.meta?.changes,
1042
+ duration: resp.meta?.duration,
1043
+ last_row_id: resp.meta?.last_row_id,
1044
+ served_by: resp.meta?.served_by,
1045
+ rowsRead: resp.meta?.rows_read,
1046
+ rowsWritten: resp.meta?.rows_written,
1047
+ meta: resp.meta,
1048
+ success: resp.success
1049
+ };
1050
1050
  }
1051
1051
  );
1052
1052
  });
1053
1053
  }
1054
1054
  };
1055
1055
 
1056
- // src/databases/pg.ts
1057
- var PGQB = class extends QueryBuilder {
1058
- db;
1059
- _migrationsBuilder = asyncMigrationsBuilder;
1060
- constructor(db, options) {
1061
- super(options);
1062
- this.db = db;
1063
- }
1064
- migrations(options) {
1065
- return new asyncMigrationsBuilder(options, this);
1066
- }
1067
- async connect() {
1068
- await this.db.connect();
1069
- }
1070
- async close() {
1071
- await this.db.end();
1072
- }
1073
- async execute(query) {
1074
- return await this.loggerWrapper(query, this.options.logger, async () => {
1075
- const queryString = query.query.replaceAll("?", "$");
1076
- let result;
1077
- if (query.arguments) {
1078
- result = await this.db.query({
1079
- values: query.arguments,
1080
- text: queryString
1081
- });
1082
- } else {
1083
- result = await this.db.query({
1084
- text: queryString
1085
- });
1086
- }
1087
- if (query.fetchType === "ONE" /* ONE */ || query.fetchType === "ALL" /* ALL */) {
1088
- return {
1089
- command: result.command,
1090
- lastRowId: result.oid,
1091
- rowCount: result.rowCount,
1092
- results: query.fetchType === "ONE" /* ONE */ ? result.rows[0] : result.rows
1093
- };
1094
- }
1095
- return {
1096
- command: result.command,
1097
- lastRowId: result.oid,
1098
- rowCount: result.rowCount
1099
- };
1100
- });
1101
- }
1102
- };
1103
-
1104
1056
  // src/databases/do.ts
1105
1057
  var DOQB = class extends QueryBuilder {
1106
1058
  db;
@@ -1149,6 +1101,54 @@ var DOQB = class extends QueryBuilder {
1149
1101
  });
1150
1102
  }
1151
1103
  };
1104
+
1105
+ // src/databases/pg.ts
1106
+ var PGQB = class extends QueryBuilder {
1107
+ db;
1108
+ _migrationsBuilder = asyncMigrationsBuilder;
1109
+ constructor(db, options) {
1110
+ super(options);
1111
+ this.db = db;
1112
+ }
1113
+ migrations(options) {
1114
+ return new asyncMigrationsBuilder(options, this);
1115
+ }
1116
+ async connect() {
1117
+ await this.db.connect();
1118
+ }
1119
+ async close() {
1120
+ await this.db.end();
1121
+ }
1122
+ async execute(query) {
1123
+ return await this.loggerWrapper(query, this.options.logger, async () => {
1124
+ const queryString = query.query.replaceAll("?", "$");
1125
+ let result;
1126
+ if (query.arguments) {
1127
+ result = await this.db.query({
1128
+ values: query.arguments,
1129
+ text: queryString
1130
+ });
1131
+ } else {
1132
+ result = await this.db.query({
1133
+ text: queryString
1134
+ });
1135
+ }
1136
+ if (query.fetchType === "ONE" /* ONE */ || query.fetchType === "ALL" /* ALL */) {
1137
+ return {
1138
+ command: result.command,
1139
+ lastRowId: result.oid,
1140
+ rowCount: result.rowCount,
1141
+ results: query.fetchType === "ONE" /* ONE */ ? result.rows[0] : result.rows
1142
+ };
1143
+ }
1144
+ return {
1145
+ command: result.command,
1146
+ lastRowId: result.oid,
1147
+ rowCount: result.rowCount
1148
+ };
1149
+ });
1150
+ }
1151
+ };
1152
1152
  // Annotate the CommonJS export names for ESM import in node:
1153
1153
  0 && (module.exports = {
1154
1154
  ConflictTypes,
package/dist/index.mjs CHANGED
@@ -573,7 +573,8 @@ var QueryBuilder = class {
573
573
  }
574
574
  const columns = Object.keys(data[0]).join(", ");
575
575
  let index = 1;
576
- let orConflict = "", onConflict = "";
576
+ let orConflict = "";
577
+ let onConflict = "";
577
578
  if (params.onConflict && typeof params.onConflict === "object") {
578
579
  onConflict = this._onConflict(params.onConflict);
579
580
  if (typeof params.onConflict?.where === "object" && !Array.isArray(params.onConflict?.where) && params.onConflict?.where?.params) {
@@ -628,11 +629,12 @@ var QueryBuilder = class {
628
629
  FROM ${params.tableName}` + this._where(params.where) + this._returning(params.returning) + this._orderBy(params.orderBy) + this._limit(params.limit) + this._offset(params.offset);
629
630
  }
630
631
  _select(params, queryArgs) {
632
+ let newQueryArgs = queryArgs;
631
633
  const isTopLevelCall = queryArgs === void 0;
632
634
  if (isTopLevelCall) {
633
- queryArgs = [];
635
+ newQueryArgs = [];
634
636
  }
635
- const currentQueryArgs = queryArgs;
637
+ const currentQueryArgs = newQueryArgs;
636
638
  const context = {
637
639
  subQueryPlaceholders: params.subQueryPlaceholders,
638
640
  queryArgs: currentQueryArgs,
@@ -806,9 +808,8 @@ var QueryBuilder = class {
806
808
  objs.push(`${key} ${item}`);
807
809
  });
808
810
  return objs.join(", ");
809
- } else {
810
- return obj;
811
811
  }
812
+ return obj;
812
813
  });
813
814
  return ` ORDER BY ${result.join(", ")}`;
814
815
  }
@@ -993,72 +994,23 @@ var D1QB = class extends QueryBuilder {
993
994
  success: resp.success,
994
995
  results: queryArray[i]?.fetchType === "ONE" /* ONE */ ? resp.results?.[0] : resp.results
995
996
  };
996
- } else {
997
- return {
998
- changes: resp.meta?.changes,
999
- duration: resp.meta?.duration,
1000
- last_row_id: resp.meta?.last_row_id,
1001
- served_by: resp.meta?.served_by,
1002
- rowsRead: resp.meta?.rows_read,
1003
- rowsWritten: resp.meta?.rows_written,
1004
- meta: resp.meta,
1005
- success: resp.success
1006
- };
1007
997
  }
998
+ return {
999
+ changes: resp.meta?.changes,
1000
+ duration: resp.meta?.duration,
1001
+ last_row_id: resp.meta?.last_row_id,
1002
+ served_by: resp.meta?.served_by,
1003
+ rowsRead: resp.meta?.rows_read,
1004
+ rowsWritten: resp.meta?.rows_written,
1005
+ meta: resp.meta,
1006
+ success: resp.success
1007
+ };
1008
1008
  }
1009
1009
  );
1010
1010
  });
1011
1011
  }
1012
1012
  };
1013
1013
 
1014
- // src/databases/pg.ts
1015
- var PGQB = class extends QueryBuilder {
1016
- db;
1017
- _migrationsBuilder = asyncMigrationsBuilder;
1018
- constructor(db, options) {
1019
- super(options);
1020
- this.db = db;
1021
- }
1022
- migrations(options) {
1023
- return new asyncMigrationsBuilder(options, this);
1024
- }
1025
- async connect() {
1026
- await this.db.connect();
1027
- }
1028
- async close() {
1029
- await this.db.end();
1030
- }
1031
- async execute(query) {
1032
- return await this.loggerWrapper(query, this.options.logger, async () => {
1033
- const queryString = query.query.replaceAll("?", "$");
1034
- let result;
1035
- if (query.arguments) {
1036
- result = await this.db.query({
1037
- values: query.arguments,
1038
- text: queryString
1039
- });
1040
- } else {
1041
- result = await this.db.query({
1042
- text: queryString
1043
- });
1044
- }
1045
- if (query.fetchType === "ONE" /* ONE */ || query.fetchType === "ALL" /* ALL */) {
1046
- return {
1047
- command: result.command,
1048
- lastRowId: result.oid,
1049
- rowCount: result.rowCount,
1050
- results: query.fetchType === "ONE" /* ONE */ ? result.rows[0] : result.rows
1051
- };
1052
- }
1053
- return {
1054
- command: result.command,
1055
- lastRowId: result.oid,
1056
- rowCount: result.rowCount
1057
- };
1058
- });
1059
- }
1060
- };
1061
-
1062
1014
  // src/databases/do.ts
1063
1015
  var DOQB = class extends QueryBuilder {
1064
1016
  db;
@@ -1107,6 +1059,54 @@ var DOQB = class extends QueryBuilder {
1107
1059
  });
1108
1060
  }
1109
1061
  };
1062
+
1063
+ // src/databases/pg.ts
1064
+ var PGQB = class extends QueryBuilder {
1065
+ db;
1066
+ _migrationsBuilder = asyncMigrationsBuilder;
1067
+ constructor(db, options) {
1068
+ super(options);
1069
+ this.db = db;
1070
+ }
1071
+ migrations(options) {
1072
+ return new asyncMigrationsBuilder(options, this);
1073
+ }
1074
+ async connect() {
1075
+ await this.db.connect();
1076
+ }
1077
+ async close() {
1078
+ await this.db.end();
1079
+ }
1080
+ async execute(query) {
1081
+ return await this.loggerWrapper(query, this.options.logger, async () => {
1082
+ const queryString = query.query.replaceAll("?", "$");
1083
+ let result;
1084
+ if (query.arguments) {
1085
+ result = await this.db.query({
1086
+ values: query.arguments,
1087
+ text: queryString
1088
+ });
1089
+ } else {
1090
+ result = await this.db.query({
1091
+ text: queryString
1092
+ });
1093
+ }
1094
+ if (query.fetchType === "ONE" /* ONE */ || query.fetchType === "ALL" /* ALL */) {
1095
+ return {
1096
+ command: result.command,
1097
+ lastRowId: result.oid,
1098
+ rowCount: result.rowCount,
1099
+ results: query.fetchType === "ONE" /* ONE */ ? result.rows[0] : result.rows
1100
+ };
1101
+ }
1102
+ return {
1103
+ command: result.command,
1104
+ lastRowId: result.oid,
1105
+ rowCount: result.rowCount
1106
+ };
1107
+ });
1108
+ }
1109
+ };
1110
1110
  export {
1111
1111
  ConflictTypes,
1112
1112
  D1QB,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workers-qb",
3
- "version": "1.11.1",
3
+ "version": "1.11.2",
4
4
  "description": "Zero dependencies Query Builder for Cloudflare Workers",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -61,13 +61,12 @@
61
61
  "url": "https://github.com/G4brym/workers-qb/issues"
62
62
  },
63
63
  "devDependencies": {
64
- "@biomejs/biome": "1.9.4",
65
- "@cloudflare/vitest-pool-workers": "^0.8.64",
66
- "@cloudflare/workers-types": "^4.20250816.0",
64
+ "@biomejs/biome": "2.2.3",
65
+ "@cloudflare/vitest-pool-workers": "^0.8.70",
66
+ "@cloudflare/workers-types": "^4.20250906.0",
67
67
  "tsup": "^8.5.0",
68
68
  "typescript": "^5.9.2",
69
69
  "vitepress": "^1.6.4",
70
- "vitest": "^3.2.4",
71
- "wrangler": "^4.30.0"
70
+ "wrangler": "^4.34.0"
72
71
  }
73
72
  }