workers-qb 1.11.0 → 1.11.1
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 +23 -6
- package/dist/index.d.ts +23 -6
- package/dist/index.js +19 -6
- package/dist/index.mjs +19 -6
- 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 -8
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,9 +331,14 @@ 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>;
|
|
@@ -343,13 +354,19 @@ declare class PGQB extends QueryBuilder<PGResult> {
|
|
|
343
354
|
execute(query: Query): Promise<any>;
|
|
344
355
|
}
|
|
345
356
|
|
|
346
|
-
|
|
347
|
-
|
|
357
|
+
interface SqlStorage {
|
|
358
|
+
exec: any;
|
|
359
|
+
prepare: any;
|
|
360
|
+
Cursor: any;
|
|
361
|
+
Statement: any;
|
|
362
|
+
}
|
|
363
|
+
declare class DOQB extends QueryBuilder<DOResult, false> {
|
|
364
|
+
db: SqlStorage;
|
|
348
365
|
loggerWrapper: typeof syncLoggerWrapper;
|
|
349
|
-
constructor(db:
|
|
350
|
-
migrations(options: MigrationOptions): syncMigrationsBuilder<
|
|
366
|
+
constructor(db: SqlStorage, options?: QueryBuilderOptions<false>);
|
|
367
|
+
migrations(options: MigrationOptions): syncMigrationsBuilder<DOResult>;
|
|
351
368
|
execute(query: Query<any, false>): any;
|
|
352
369
|
lazyExecute(query: Query<any, false>): Iterable<any>;
|
|
353
370
|
}
|
|
354
371
|
|
|
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,9 +331,14 @@ 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>;
|
|
@@ -343,13 +354,19 @@ declare class PGQB extends QueryBuilder<PGResult> {
|
|
|
343
354
|
execute(query: Query): Promise<any>;
|
|
344
355
|
}
|
|
345
356
|
|
|
346
|
-
|
|
347
|
-
|
|
357
|
+
interface SqlStorage {
|
|
358
|
+
exec: any;
|
|
359
|
+
prepare: any;
|
|
360
|
+
Cursor: any;
|
|
361
|
+
Statement: any;
|
|
362
|
+
}
|
|
363
|
+
declare class DOQB extends QueryBuilder<DOResult, false> {
|
|
364
|
+
db: SqlStorage;
|
|
348
365
|
loggerWrapper: typeof syncLoggerWrapper;
|
|
349
|
-
constructor(db:
|
|
350
|
-
migrations(options: MigrationOptions): syncMigrationsBuilder<
|
|
366
|
+
constructor(db: SqlStorage, options?: QueryBuilderOptions<false>);
|
|
367
|
+
migrations(options: MigrationOptions): syncMigrationsBuilder<DOResult>;
|
|
351
368
|
execute(query: Query<any, false>): any;
|
|
352
369
|
lazyExecute(query: Query<any, false>): Iterable<any>;
|
|
353
370
|
}
|
|
354
371
|
|
|
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
|
@@ -995,11 +995,14 @@ var D1QB = class extends QueryBuilder {
|
|
|
995
995
|
}
|
|
996
996
|
if (query.fetchType === "ONE" /* ONE */ || query.fetchType === "ALL" /* ALL */) {
|
|
997
997
|
const resp = await stmt.all();
|
|
998
|
+
const meta = resp.meta;
|
|
998
999
|
return {
|
|
999
|
-
changes:
|
|
1000
|
-
duration:
|
|
1001
|
-
last_row_id:
|
|
1002
|
-
served_by:
|
|
1000
|
+
changes: meta?.changes,
|
|
1001
|
+
duration: meta?.duration,
|
|
1002
|
+
last_row_id: meta?.last_row_id,
|
|
1003
|
+
served_by: meta?.served_by,
|
|
1004
|
+
rowsRead: meta?.rows_read,
|
|
1005
|
+
rowsWritten: meta?.rows_written,
|
|
1003
1006
|
meta: resp.meta,
|
|
1004
1007
|
success: resp.success,
|
|
1005
1008
|
results: query.fetchType === "ONE" /* ONE */ ? resp.results[0] : resp.results
|
|
@@ -1026,6 +1029,8 @@ var D1QB = class extends QueryBuilder {
|
|
|
1026
1029
|
duration: resp.meta?.duration,
|
|
1027
1030
|
last_row_id: resp.meta?.last_row_id,
|
|
1028
1031
|
served_by: resp.meta?.served_by,
|
|
1032
|
+
rowsRead: resp.meta?.rows_read,
|
|
1033
|
+
rowsWritten: resp.meta?.rows_written,
|
|
1029
1034
|
meta: resp.meta,
|
|
1030
1035
|
success: resp.success,
|
|
1031
1036
|
results: queryArray[i]?.fetchType === "ONE" /* ONE */ ? resp.results?.[0] : resp.results
|
|
@@ -1036,6 +1041,8 @@ var D1QB = class extends QueryBuilder {
|
|
|
1036
1041
|
duration: resp.meta?.duration,
|
|
1037
1042
|
last_row_id: resp.meta?.last_row_id,
|
|
1038
1043
|
served_by: resp.meta?.served_by,
|
|
1044
|
+
rowsRead: resp.meta?.rows_read,
|
|
1045
|
+
rowsWritten: resp.meta?.rows_written,
|
|
1039
1046
|
meta: resp.meta,
|
|
1040
1047
|
success: resp.success
|
|
1041
1048
|
};
|
|
@@ -1114,13 +1121,19 @@ var DOQB = class extends QueryBuilder {
|
|
|
1114
1121
|
cursor = this.db.exec(query.query);
|
|
1115
1122
|
}
|
|
1116
1123
|
const result = cursor.toArray();
|
|
1124
|
+
const rowsRead = cursor.rowsRead;
|
|
1125
|
+
const rowsWritten = cursor.rowsWritten;
|
|
1117
1126
|
if (query.fetchType == "ONE" /* ONE */) {
|
|
1118
1127
|
return {
|
|
1119
|
-
results: result.length > 0 ? result[0] : void 0
|
|
1128
|
+
results: result.length > 0 ? result[0] : void 0,
|
|
1129
|
+
rowsRead,
|
|
1130
|
+
rowsWritten
|
|
1120
1131
|
};
|
|
1121
1132
|
}
|
|
1122
1133
|
return {
|
|
1123
|
-
results: result
|
|
1134
|
+
results: result,
|
|
1135
|
+
rowsRead,
|
|
1136
|
+
rowsWritten
|
|
1124
1137
|
};
|
|
1125
1138
|
});
|
|
1126
1139
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -953,11 +953,14 @@ var D1QB = class extends QueryBuilder {
|
|
|
953
953
|
}
|
|
954
954
|
if (query.fetchType === "ONE" /* ONE */ || query.fetchType === "ALL" /* ALL */) {
|
|
955
955
|
const resp = await stmt.all();
|
|
956
|
+
const meta = resp.meta;
|
|
956
957
|
return {
|
|
957
|
-
changes:
|
|
958
|
-
duration:
|
|
959
|
-
last_row_id:
|
|
960
|
-
served_by:
|
|
958
|
+
changes: meta?.changes,
|
|
959
|
+
duration: meta?.duration,
|
|
960
|
+
last_row_id: meta?.last_row_id,
|
|
961
|
+
served_by: meta?.served_by,
|
|
962
|
+
rowsRead: meta?.rows_read,
|
|
963
|
+
rowsWritten: meta?.rows_written,
|
|
961
964
|
meta: resp.meta,
|
|
962
965
|
success: resp.success,
|
|
963
966
|
results: query.fetchType === "ONE" /* ONE */ ? resp.results[0] : resp.results
|
|
@@ -984,6 +987,8 @@ var D1QB = class extends QueryBuilder {
|
|
|
984
987
|
duration: resp.meta?.duration,
|
|
985
988
|
last_row_id: resp.meta?.last_row_id,
|
|
986
989
|
served_by: resp.meta?.served_by,
|
|
990
|
+
rowsRead: resp.meta?.rows_read,
|
|
991
|
+
rowsWritten: resp.meta?.rows_written,
|
|
987
992
|
meta: resp.meta,
|
|
988
993
|
success: resp.success,
|
|
989
994
|
results: queryArray[i]?.fetchType === "ONE" /* ONE */ ? resp.results?.[0] : resp.results
|
|
@@ -994,6 +999,8 @@ var D1QB = class extends QueryBuilder {
|
|
|
994
999
|
duration: resp.meta?.duration,
|
|
995
1000
|
last_row_id: resp.meta?.last_row_id,
|
|
996
1001
|
served_by: resp.meta?.served_by,
|
|
1002
|
+
rowsRead: resp.meta?.rows_read,
|
|
1003
|
+
rowsWritten: resp.meta?.rows_written,
|
|
997
1004
|
meta: resp.meta,
|
|
998
1005
|
success: resp.success
|
|
999
1006
|
};
|
|
@@ -1072,13 +1079,19 @@ var DOQB = class extends QueryBuilder {
|
|
|
1072
1079
|
cursor = this.db.exec(query.query);
|
|
1073
1080
|
}
|
|
1074
1081
|
const result = cursor.toArray();
|
|
1082
|
+
const rowsRead = cursor.rowsRead;
|
|
1083
|
+
const rowsWritten = cursor.rowsWritten;
|
|
1075
1084
|
if (query.fetchType == "ONE" /* ONE */) {
|
|
1076
1085
|
return {
|
|
1077
|
-
results: result.length > 0 ? result[0] : void 0
|
|
1086
|
+
results: result.length > 0 ? result[0] : void 0,
|
|
1087
|
+
rowsRead,
|
|
1088
|
+
rowsWritten
|
|
1078
1089
|
};
|
|
1079
1090
|
}
|
|
1080
1091
|
return {
|
|
1081
|
-
results: result
|
|
1092
|
+
results: result,
|
|
1093
|
+
rowsRead,
|
|
1094
|
+
rowsWritten
|
|
1082
1095
|
};
|
|
1083
1096
|
});
|
|
1084
1097
|
}
|