From 8bb020af3ebc60c69aa4b6e7c6c7e789ff06fc7d Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Wed, 17 Jul 2024 21:44:46 +0100 Subject: [PATCH] Add remaining D1 meta properties to the returning object --- src/databases/d1.ts | 3 +++ src/interfaces.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/databases/d1.ts b/src/databases/d1.ts index 31873e7..3385334 100644 --- a/src/databases/d1.ts +++ b/src/databases/d1.ts @@ -36,6 +36,7 @@ export class D1QB extends QueryBuilder { duration: resp.meta?.duration, last_row_id: resp.meta?.last_row_id, served_by: resp.meta?.served_by, + meta: resp.meta, success: resp.success, results: query.fetchType === FetchTypes.ONE ? resp.results[0] : resp.results, } @@ -81,6 +82,7 @@ export class D1QB extends QueryBuilder { duration: resp.meta?.duration, last_row_id: resp.meta?.last_row_id, served_by: resp.meta?.served_by, + meta: resp.meta, success: resp.success, results: queryArray[i]?.fetchType === FetchTypes.ONE ? resp.results?.[0] : resp.results, } @@ -90,6 +92,7 @@ export class D1QB extends QueryBuilder { duration: resp.meta?.duration, last_row_id: resp.meta?.last_row_id, served_by: resp.meta?.served_by, + meta: resp.meta, success: resp.success, } } diff --git a/src/interfaces.ts b/src/interfaces.ts index dae220a..974beb4 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -105,11 +105,25 @@ export type DeleteReturning = Omit & { } export type DeleteWithoutReturning = Omit +export type D1Meta = { + changed_db: boolean + changes: number + duration: number + last_row_id: string | number + rows_read: number + rows_written: number + served_by: string + size_after: number +} + export type D1Result = { + // These 4 fields are deprecated, and only kept here for retro compatibility, users should use the meta field bellow changes?: number duration: number last_row_id?: string | number served_by: string + + meta?: D1Meta success: boolean }