Skip to content

Commit

Permalink
Add remaining D1 meta properties to the returning object (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym authored Jul 17, 2024
1 parent 12daee3 commit de9c1b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/databases/d1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class D1QB extends QueryBuilder<D1Result> {
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,
}
Expand Down Expand Up @@ -81,6 +82,7 @@ export class D1QB extends QueryBuilder<D1Result> {
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,
}
Expand All @@ -90,6 +92,7 @@ export class D1QB extends QueryBuilder<D1Result> {
duration: resp.meta?.duration,
last_row_id: resp.meta?.last_row_id,
served_by: resp.meta?.served_by,
meta: resp.meta,
success: resp.success,
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,25 @@ export type DeleteReturning = Omit<Delete, 'returning'> & {
}
export type DeleteWithoutReturning = Omit<Delete, 'returning'>

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
}

Expand Down

0 comments on commit de9c1b5

Please sign in to comment.