workers-qb
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -0,1 +1,3 @@ | ||
import { SqlStorage } from '@cloudflare/workers-types/experimental'; | ||
declare enum OrderTypes { | ||
@@ -248,2 +250,12 @@ ASC = "ASC", | ||
export { type ArrayResult, ConflictTypes, type ConflictUpsert, type D1Meta, D1QB, type D1Result, type DefaultObject, type DefaultReturnObject, type Delete, type DeleteReturning, type DeleteWithoutReturning, 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 }; | ||
declare class DurableObjectDatabaseQB extends QueryBuilder<{}> { | ||
db: SqlStorage; | ||
constructor(db: SqlStorage); | ||
execute(query: Query): Promise<{ | ||
results: Record<string, string | number | ArrayBuffer | null> | undefined; | ||
} | { | ||
results: Record<string, string | number | ArrayBuffer | null>[]; | ||
}>; | ||
} | ||
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 }; |
@@ -25,2 +25,3 @@ "use strict"; | ||
D1QB: () => D1QB, | ||
DurableObjectDatabaseQB: () => DurableObjectDatabaseQB, | ||
FetchTypes: () => FetchTypes, | ||
@@ -602,2 +603,43 @@ JoinTypes: () => JoinTypes, | ||
}; | ||
// src/databases/do.ts | ||
var DurableObjectDatabaseQB = class extends QueryBuilder { | ||
db; | ||
constructor(db) { | ||
super(); | ||
this.db = db; | ||
} | ||
async execute(query) { | ||
if (this._debugger) { | ||
console.log({ | ||
"workers-qb": { | ||
query: query.query, | ||
arguments: query.arguments, | ||
fetchType: query.fetchType | ||
} | ||
}); | ||
} | ||
if (query.arguments) { | ||
let stmt = this.db.prepare(query.query); | ||
const result = stmt(...query.arguments); | ||
if (query.fetchType == "ONE" /* ONE */) { | ||
return { | ||
results: Array.from(result)[0] | ||
}; | ||
} | ||
return { | ||
results: Array.from(result) | ||
}; | ||
} | ||
const cursor = this.db.exec(query.query); | ||
if (query.fetchType == "ONE" /* ONE */) { | ||
return { | ||
results: Array.from(cursor)[0] | ||
}; | ||
} | ||
return { | ||
results: Array.from(cursor) | ||
}; | ||
} | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -607,2 +649,3 @@ 0 && (module.exports = { | ||
D1QB, | ||
DurableObjectDatabaseQB, | ||
FetchTypes, | ||
@@ -609,0 +652,0 @@ JoinTypes, |
{ | ||
"name": "workers-qb", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Zero dependencies Query Builder for Cloudflare Workers", | ||
@@ -59,2 +59,3 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20240815.0", | ||
"@types/jest": "^29.5.12", | ||
@@ -61,0 +62,0 @@ "@typescript-eslint/eslint-plugin": "^4.31.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
63007
1512
15