Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remaining D1 meta properties to the returning object #48

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading