Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
Added D1Database and related types (#265)
Browse files Browse the repository at this point in the history
Co-authored-by: Glen Maddern <glen@cloudflare.com>
  • Loading branch information
geelen and geelen committed Aug 2, 2022
1 parent 38b7e0f commit 6cac151
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-tables-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/workers-types": minor
---

Added D1 binding types
25 changes: 25 additions & 0 deletions overrides/d1.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
declare type D1Result<T = unknown> = {
results?: T[];
lastRowId: number | null;
changes: number;
duration: number;
error?: string;
};
declare abstract class D1Database {
prepare(query: string): D1PreparedStatement;
dump(): Promise<ArrayBuffer>;
batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
exec<T = unknown>(query: string): Promise<D1Result<T>>;
_send<T = unknown>(
endpoint: string,
query: any,
params: any[]
): Promise<D1Result<T>[] | D1Result<T>>;
}
declare abstract class D1PreparedStatement {
bind(...values: any[]): D1PreparedStatement;
first<T = unknown>(colName?: string): Promise<T>;
run<T = unknown>(): Promise<D1Result<T>>;
all<T = unknown>(): Promise<D1Result<T[]>>;
raw<T = unknown>(): Promise<T[]>;
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6cac151

Please sign in to comment.