workers-qb 1.11.0 → 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 +3 -3
- package/dist/index.d.mts +28 -11
- package/dist/index.d.ts +28 -11
- package/dist/index.js +74 -61
- package/dist/index.mjs +74 -61
- package/docs/advanced-queries.md +602 -0
- package/docs/background-writes.md +119 -0
- package/docs/basic-queries.md +527 -0
- package/docs/databases/byodb.md +108 -0
- package/docs/databases/d1.md +229 -0
- package/docs/databases/do.md +266 -0
- package/docs/databases/postgresql.md +206 -0
- package/docs/index.md +32 -0
- package/docs/introduction.md +93 -0
- package/docs/json-queries.md +142 -0
- package/docs/logger.md +45 -0
- package/docs/migrations.md +133 -0
- package/docs/type-check.md +122 -0
- package/package.json +15 -9
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/
|
|
39
|
-
- 💾 [Cloudflare Durable Objects](https://workers-qb.massadas.com/databases/
|
|
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/
|
|
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
|
@@ -196,9 +196,15 @@ type D1Result = {
|
|
|
196
196
|
duration: number;
|
|
197
197
|
last_row_id?: string | number;
|
|
198
198
|
served_by: string;
|
|
199
|
+
rowsRead?: number;
|
|
200
|
+
rowsWritten?: number;
|
|
199
201
|
meta?: D1Meta;
|
|
200
202
|
success: boolean;
|
|
201
203
|
};
|
|
204
|
+
type DOResult = {
|
|
205
|
+
rowsRead: number;
|
|
206
|
+
rowsWritten: number;
|
|
207
|
+
};
|
|
202
208
|
type PGResult = {
|
|
203
209
|
command: string;
|
|
204
210
|
lastRowId?: string | number;
|
|
@@ -325,14 +331,34 @@ declare class asyncMigrationsBuilder<GenericResultWrapper> {
|
|
|
325
331
|
apply(): Promise<Array<Migration>>;
|
|
326
332
|
}
|
|
327
333
|
|
|
334
|
+
interface D1Database {
|
|
335
|
+
prepare: any;
|
|
336
|
+
batch: any;
|
|
337
|
+
exec: any;
|
|
338
|
+
}
|
|
328
339
|
declare class D1QB extends QueryBuilder<D1Result> {
|
|
329
340
|
db: any;
|
|
330
|
-
constructor(db:
|
|
341
|
+
constructor(db: D1Database, options?: QueryBuilderOptions);
|
|
331
342
|
migrations(options: MigrationOptions): asyncMigrationsBuilder<D1Result>;
|
|
332
343
|
execute(query: Query): Promise<any>;
|
|
333
344
|
batchExecute(queryArray: Query[]): Promise<any>;
|
|
334
345
|
}
|
|
335
346
|
|
|
347
|
+
interface SqlStorage {
|
|
348
|
+
exec: any;
|
|
349
|
+
get databaseSize(): number;
|
|
350
|
+
Cursor: any;
|
|
351
|
+
Statement: any;
|
|
352
|
+
}
|
|
353
|
+
declare class DOQB extends QueryBuilder<DOResult, false> {
|
|
354
|
+
db: SqlStorage;
|
|
355
|
+
loggerWrapper: typeof syncLoggerWrapper;
|
|
356
|
+
constructor(db: SqlStorage, options?: QueryBuilderOptions<false>);
|
|
357
|
+
migrations(options: MigrationOptions): syncMigrationsBuilder<DOResult>;
|
|
358
|
+
execute(query: Query<any, false>): any;
|
|
359
|
+
lazyExecute(query: Query<any, false>): Iterable<any>;
|
|
360
|
+
}
|
|
361
|
+
|
|
336
362
|
declare class PGQB extends QueryBuilder<PGResult> {
|
|
337
363
|
db: any;
|
|
338
364
|
_migrationsBuilder: typeof asyncMigrationsBuilder;
|
|
@@ -343,13 +369,4 @@ declare class PGQB extends QueryBuilder<PGResult> {
|
|
|
343
369
|
execute(query: Query): Promise<any>;
|
|
344
370
|
}
|
|
345
371
|
|
|
346
|
-
|
|
347
|
-
db: any;
|
|
348
|
-
loggerWrapper: typeof syncLoggerWrapper;
|
|
349
|
-
constructor(db: any, options?: QueryBuilderOptions<false>);
|
|
350
|
-
migrations(options: MigrationOptions): syncMigrationsBuilder<{}>;
|
|
351
|
-
execute(query: Query<any, false>): any;
|
|
352
|
-
lazyExecute(query: Query<any, false>): Iterable<any>;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export { type ArrayResult, type AsyncType, ConflictTypes, type ConflictUpsert, type CountResult, type D1Meta, D1QB, type D1Result, DOQB, 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 };
|
|
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
|
@@ -196,9 +196,15 @@ type D1Result = {
|
|
|
196
196
|
duration: number;
|
|
197
197
|
last_row_id?: string | number;
|
|
198
198
|
served_by: string;
|
|
199
|
+
rowsRead?: number;
|
|
200
|
+
rowsWritten?: number;
|
|
199
201
|
meta?: D1Meta;
|
|
200
202
|
success: boolean;
|
|
201
203
|
};
|
|
204
|
+
type DOResult = {
|
|
205
|
+
rowsRead: number;
|
|
206
|
+
rowsWritten: number;
|
|
207
|
+
};
|
|
202
208
|
type PGResult = {
|
|
203
209
|
command: string;
|
|
204
210
|
lastRowId?: string | number;
|
|
@@ -325,14 +331,34 @@ declare class asyncMigrationsBuilder<GenericResultWrapper> {
|
|
|
325
331
|
apply(): Promise<Array<Migration>>;
|
|
326
332
|
}
|
|
327
333
|
|
|
334
|
+
interface D1Database {
|
|
335
|
+
prepare: any;
|
|
336
|
+
batch: any;
|
|
337
|
+
exec: any;
|
|
338
|
+
}
|
|
328
339
|
declare class D1QB extends QueryBuilder<D1Result> {
|
|
329
340
|
db: any;
|
|
330
|
-
constructor(db:
|
|
341
|
+
constructor(db: D1Database, options?: QueryBuilderOptions);
|
|
331
342
|
migrations(options: MigrationOptions): asyncMigrationsBuilder<D1Result>;
|
|
332
343
|
execute(query: Query): Promise<any>;
|
|
333
344
|
batchExecute(queryArray: Query[]): Promise<any>;
|
|
334
345
|
}
|
|
335
346
|
|
|
347
|
+
interface SqlStorage {
|
|
348
|
+
exec: any;
|
|
349
|
+
get databaseSize(): number;
|
|
350
|
+
Cursor: any;
|
|
351
|
+
Statement: any;
|
|
352
|
+
}
|
|
353
|
+
declare class DOQB extends QueryBuilder<DOResult, false> {
|
|
354
|
+
db: SqlStorage;
|
|
355
|
+
loggerWrapper: typeof syncLoggerWrapper;
|
|
356
|
+
constructor(db: SqlStorage, options?: QueryBuilderOptions<false>);
|
|
357
|
+
migrations(options: MigrationOptions): syncMigrationsBuilder<DOResult>;
|
|
358
|
+
execute(query: Query<any, false>): any;
|
|
359
|
+
lazyExecute(query: Query<any, false>): Iterable<any>;
|
|
360
|
+
}
|
|
361
|
+
|
|
336
362
|
declare class PGQB extends QueryBuilder<PGResult> {
|
|
337
363
|
db: any;
|
|
338
364
|
_migrationsBuilder: typeof asyncMigrationsBuilder;
|
|
@@ -343,13 +369,4 @@ declare class PGQB extends QueryBuilder<PGResult> {
|
|
|
343
369
|
execute(query: Query): Promise<any>;
|
|
344
370
|
}
|
|
345
371
|
|
|
346
|
-
|
|
347
|
-
db: any;
|
|
348
|
-
loggerWrapper: typeof syncLoggerWrapper;
|
|
349
|
-
constructor(db: any, options?: QueryBuilderOptions<false>);
|
|
350
|
-
migrations(options: MigrationOptions): syncMigrationsBuilder<{}>;
|
|
351
|
-
execute(query: Query<any, false>): any;
|
|
352
|
-
lazyExecute(query: Query<any, false>): Iterable<any>;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export { type ArrayResult, type AsyncType, ConflictTypes, type ConflictUpsert, type CountResult, type D1Meta, D1QB, type D1Result, DOQB, 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 };
|
|
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 = ""
|
|
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
|
-
|
|
677
|
+
newQueryArgs = [];
|
|
676
678
|
}
|
|
677
|
-
const currentQueryArgs =
|
|
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
|
}
|
|
@@ -995,11 +996,14 @@ var D1QB = class extends QueryBuilder {
|
|
|
995
996
|
}
|
|
996
997
|
if (query.fetchType === "ONE" /* ONE */ || query.fetchType === "ALL" /* ALL */) {
|
|
997
998
|
const resp = await stmt.all();
|
|
999
|
+
const meta = resp.meta;
|
|
998
1000
|
return {
|
|
999
|
-
changes:
|
|
1000
|
-
duration:
|
|
1001
|
-
last_row_id:
|
|
1002
|
-
served_by:
|
|
1001
|
+
changes: meta?.changes,
|
|
1002
|
+
duration: meta?.duration,
|
|
1003
|
+
last_row_id: meta?.last_row_id,
|
|
1004
|
+
served_by: meta?.served_by,
|
|
1005
|
+
rowsRead: meta?.rows_read,
|
|
1006
|
+
rowsWritten: meta?.rows_written,
|
|
1003
1007
|
meta: resp.meta,
|
|
1004
1008
|
success: resp.success,
|
|
1005
1009
|
results: query.fetchType === "ONE" /* ONE */ ? resp.results[0] : resp.results
|
|
@@ -1026,26 +1030,78 @@ var D1QB = class extends QueryBuilder {
|
|
|
1026
1030
|
duration: resp.meta?.duration,
|
|
1027
1031
|
last_row_id: resp.meta?.last_row_id,
|
|
1028
1032
|
served_by: resp.meta?.served_by,
|
|
1033
|
+
rowsRead: resp.meta?.rows_read,
|
|
1034
|
+
rowsWritten: resp.meta?.rows_written,
|
|
1029
1035
|
meta: resp.meta,
|
|
1030
1036
|
success: resp.success,
|
|
1031
1037
|
results: queryArray[i]?.fetchType === "ONE" /* ONE */ ? resp.results?.[0] : resp.results
|
|
1032
1038
|
};
|
|
1033
|
-
} else {
|
|
1034
|
-
return {
|
|
1035
|
-
changes: resp.meta?.changes,
|
|
1036
|
-
duration: resp.meta?.duration,
|
|
1037
|
-
last_row_id: resp.meta?.last_row_id,
|
|
1038
|
-
served_by: resp.meta?.served_by,
|
|
1039
|
-
meta: resp.meta,
|
|
1040
|
-
success: resp.success
|
|
1041
|
-
};
|
|
1042
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
|
+
};
|
|
1043
1050
|
}
|
|
1044
1051
|
);
|
|
1045
1052
|
});
|
|
1046
1053
|
}
|
|
1047
1054
|
};
|
|
1048
1055
|
|
|
1056
|
+
// src/databases/do.ts
|
|
1057
|
+
var DOQB = class extends QueryBuilder {
|
|
1058
|
+
db;
|
|
1059
|
+
loggerWrapper = syncLoggerWrapper;
|
|
1060
|
+
constructor(db, options) {
|
|
1061
|
+
super(options);
|
|
1062
|
+
this.db = db;
|
|
1063
|
+
}
|
|
1064
|
+
migrations(options) {
|
|
1065
|
+
return new syncMigrationsBuilder(options, this);
|
|
1066
|
+
}
|
|
1067
|
+
execute(query) {
|
|
1068
|
+
return this.loggerWrapper(query, this.options.logger, () => {
|
|
1069
|
+
let cursor;
|
|
1070
|
+
if (query.arguments) {
|
|
1071
|
+
cursor = this.db.exec(query.query, ...query.arguments);
|
|
1072
|
+
} else {
|
|
1073
|
+
cursor = this.db.exec(query.query);
|
|
1074
|
+
}
|
|
1075
|
+
const result = cursor.toArray();
|
|
1076
|
+
const rowsRead = cursor.rowsRead;
|
|
1077
|
+
const rowsWritten = cursor.rowsWritten;
|
|
1078
|
+
if (query.fetchType == "ONE" /* ONE */) {
|
|
1079
|
+
return {
|
|
1080
|
+
results: result.length > 0 ? result[0] : void 0,
|
|
1081
|
+
rowsRead,
|
|
1082
|
+
rowsWritten
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
return {
|
|
1086
|
+
results: result,
|
|
1087
|
+
rowsRead,
|
|
1088
|
+
rowsWritten
|
|
1089
|
+
};
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
lazyExecute(query) {
|
|
1093
|
+
return this.loggerWrapper(query, this.options.logger, () => {
|
|
1094
|
+
let cursor;
|
|
1095
|
+
if (query.arguments) {
|
|
1096
|
+
cursor = this.db.exec(query.query, ...query.arguments);
|
|
1097
|
+
} else {
|
|
1098
|
+
cursor = this.db.exec(query.query);
|
|
1099
|
+
}
|
|
1100
|
+
return cursor;
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1049
1105
|
// src/databases/pg.ts
|
|
1050
1106
|
var PGQB = class extends QueryBuilder {
|
|
1051
1107
|
db;
|
|
@@ -1093,49 +1149,6 @@ var PGQB = class extends QueryBuilder {
|
|
|
1093
1149
|
});
|
|
1094
1150
|
}
|
|
1095
1151
|
};
|
|
1096
|
-
|
|
1097
|
-
// src/databases/do.ts
|
|
1098
|
-
var DOQB = class extends QueryBuilder {
|
|
1099
|
-
db;
|
|
1100
|
-
loggerWrapper = syncLoggerWrapper;
|
|
1101
|
-
constructor(db, options) {
|
|
1102
|
-
super(options);
|
|
1103
|
-
this.db = db;
|
|
1104
|
-
}
|
|
1105
|
-
migrations(options) {
|
|
1106
|
-
return new syncMigrationsBuilder(options, this);
|
|
1107
|
-
}
|
|
1108
|
-
execute(query) {
|
|
1109
|
-
return this.loggerWrapper(query, this.options.logger, () => {
|
|
1110
|
-
let cursor;
|
|
1111
|
-
if (query.arguments) {
|
|
1112
|
-
cursor = this.db.exec(query.query, ...query.arguments);
|
|
1113
|
-
} else {
|
|
1114
|
-
cursor = this.db.exec(query.query);
|
|
1115
|
-
}
|
|
1116
|
-
const result = cursor.toArray();
|
|
1117
|
-
if (query.fetchType == "ONE" /* ONE */) {
|
|
1118
|
-
return {
|
|
1119
|
-
results: result.length > 0 ? result[0] : void 0
|
|
1120
|
-
};
|
|
1121
|
-
}
|
|
1122
|
-
return {
|
|
1123
|
-
results: result
|
|
1124
|
-
};
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1127
|
-
lazyExecute(query) {
|
|
1128
|
-
return this.loggerWrapper(query, this.options.logger, () => {
|
|
1129
|
-
let cursor;
|
|
1130
|
-
if (query.arguments) {
|
|
1131
|
-
cursor = this.db.exec(query.query, ...query.arguments);
|
|
1132
|
-
} else {
|
|
1133
|
-
cursor = this.db.exec(query.query);
|
|
1134
|
-
}
|
|
1135
|
-
return cursor;
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
};
|
|
1139
1152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1140
1153
|
0 && (module.exports = {
|
|
1141
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 = ""
|
|
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
|
-
|
|
635
|
+
newQueryArgs = [];
|
|
634
636
|
}
|
|
635
|
-
const currentQueryArgs =
|
|
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
|
}
|
|
@@ -953,11 +954,14 @@ var D1QB = class extends QueryBuilder {
|
|
|
953
954
|
}
|
|
954
955
|
if (query.fetchType === "ONE" /* ONE */ || query.fetchType === "ALL" /* ALL */) {
|
|
955
956
|
const resp = await stmt.all();
|
|
957
|
+
const meta = resp.meta;
|
|
956
958
|
return {
|
|
957
|
-
changes:
|
|
958
|
-
duration:
|
|
959
|
-
last_row_id:
|
|
960
|
-
served_by:
|
|
959
|
+
changes: meta?.changes,
|
|
960
|
+
duration: meta?.duration,
|
|
961
|
+
last_row_id: meta?.last_row_id,
|
|
962
|
+
served_by: meta?.served_by,
|
|
963
|
+
rowsRead: meta?.rows_read,
|
|
964
|
+
rowsWritten: meta?.rows_written,
|
|
961
965
|
meta: resp.meta,
|
|
962
966
|
success: resp.success,
|
|
963
967
|
results: query.fetchType === "ONE" /* ONE */ ? resp.results[0] : resp.results
|
|
@@ -984,26 +988,78 @@ var D1QB = class extends QueryBuilder {
|
|
|
984
988
|
duration: resp.meta?.duration,
|
|
985
989
|
last_row_id: resp.meta?.last_row_id,
|
|
986
990
|
served_by: resp.meta?.served_by,
|
|
991
|
+
rowsRead: resp.meta?.rows_read,
|
|
992
|
+
rowsWritten: resp.meta?.rows_written,
|
|
987
993
|
meta: resp.meta,
|
|
988
994
|
success: resp.success,
|
|
989
995
|
results: queryArray[i]?.fetchType === "ONE" /* ONE */ ? resp.results?.[0] : resp.results
|
|
990
996
|
};
|
|
991
|
-
} else {
|
|
992
|
-
return {
|
|
993
|
-
changes: resp.meta?.changes,
|
|
994
|
-
duration: resp.meta?.duration,
|
|
995
|
-
last_row_id: resp.meta?.last_row_id,
|
|
996
|
-
served_by: resp.meta?.served_by,
|
|
997
|
-
meta: resp.meta,
|
|
998
|
-
success: resp.success
|
|
999
|
-
};
|
|
1000
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
|
+
};
|
|
1001
1008
|
}
|
|
1002
1009
|
);
|
|
1003
1010
|
});
|
|
1004
1011
|
}
|
|
1005
1012
|
};
|
|
1006
1013
|
|
|
1014
|
+
// src/databases/do.ts
|
|
1015
|
+
var DOQB = class extends QueryBuilder {
|
|
1016
|
+
db;
|
|
1017
|
+
loggerWrapper = syncLoggerWrapper;
|
|
1018
|
+
constructor(db, options) {
|
|
1019
|
+
super(options);
|
|
1020
|
+
this.db = db;
|
|
1021
|
+
}
|
|
1022
|
+
migrations(options) {
|
|
1023
|
+
return new syncMigrationsBuilder(options, this);
|
|
1024
|
+
}
|
|
1025
|
+
execute(query) {
|
|
1026
|
+
return this.loggerWrapper(query, this.options.logger, () => {
|
|
1027
|
+
let cursor;
|
|
1028
|
+
if (query.arguments) {
|
|
1029
|
+
cursor = this.db.exec(query.query, ...query.arguments);
|
|
1030
|
+
} else {
|
|
1031
|
+
cursor = this.db.exec(query.query);
|
|
1032
|
+
}
|
|
1033
|
+
const result = cursor.toArray();
|
|
1034
|
+
const rowsRead = cursor.rowsRead;
|
|
1035
|
+
const rowsWritten = cursor.rowsWritten;
|
|
1036
|
+
if (query.fetchType == "ONE" /* ONE */) {
|
|
1037
|
+
return {
|
|
1038
|
+
results: result.length > 0 ? result[0] : void 0,
|
|
1039
|
+
rowsRead,
|
|
1040
|
+
rowsWritten
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
return {
|
|
1044
|
+
results: result,
|
|
1045
|
+
rowsRead,
|
|
1046
|
+
rowsWritten
|
|
1047
|
+
};
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
lazyExecute(query) {
|
|
1051
|
+
return this.loggerWrapper(query, this.options.logger, () => {
|
|
1052
|
+
let cursor;
|
|
1053
|
+
if (query.arguments) {
|
|
1054
|
+
cursor = this.db.exec(query.query, ...query.arguments);
|
|
1055
|
+
} else {
|
|
1056
|
+
cursor = this.db.exec(query.query);
|
|
1057
|
+
}
|
|
1058
|
+
return cursor;
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1007
1063
|
// src/databases/pg.ts
|
|
1008
1064
|
var PGQB = class extends QueryBuilder {
|
|
1009
1065
|
db;
|
|
@@ -1051,49 +1107,6 @@ var PGQB = class extends QueryBuilder {
|
|
|
1051
1107
|
});
|
|
1052
1108
|
}
|
|
1053
1109
|
};
|
|
1054
|
-
|
|
1055
|
-
// src/databases/do.ts
|
|
1056
|
-
var DOQB = class extends QueryBuilder {
|
|
1057
|
-
db;
|
|
1058
|
-
loggerWrapper = syncLoggerWrapper;
|
|
1059
|
-
constructor(db, options) {
|
|
1060
|
-
super(options);
|
|
1061
|
-
this.db = db;
|
|
1062
|
-
}
|
|
1063
|
-
migrations(options) {
|
|
1064
|
-
return new syncMigrationsBuilder(options, this);
|
|
1065
|
-
}
|
|
1066
|
-
execute(query) {
|
|
1067
|
-
return this.loggerWrapper(query, this.options.logger, () => {
|
|
1068
|
-
let cursor;
|
|
1069
|
-
if (query.arguments) {
|
|
1070
|
-
cursor = this.db.exec(query.query, ...query.arguments);
|
|
1071
|
-
} else {
|
|
1072
|
-
cursor = this.db.exec(query.query);
|
|
1073
|
-
}
|
|
1074
|
-
const result = cursor.toArray();
|
|
1075
|
-
if (query.fetchType == "ONE" /* ONE */) {
|
|
1076
|
-
return {
|
|
1077
|
-
results: result.length > 0 ? result[0] : void 0
|
|
1078
|
-
};
|
|
1079
|
-
}
|
|
1080
|
-
return {
|
|
1081
|
-
results: result
|
|
1082
|
-
};
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
lazyExecute(query) {
|
|
1086
|
-
return this.loggerWrapper(query, this.options.logger, () => {
|
|
1087
|
-
let cursor;
|
|
1088
|
-
if (query.arguments) {
|
|
1089
|
-
cursor = this.db.exec(query.query, ...query.arguments);
|
|
1090
|
-
} else {
|
|
1091
|
-
cursor = this.db.exec(query.query);
|
|
1092
|
-
}
|
|
1093
|
-
return cursor;
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
1110
|
export {
|
|
1098
1111
|
ConflictTypes,
|
|
1099
1112
|
D1QB,
|