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

feat: update to latest D1 Database interface #71

Merged
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
5 changes: 5 additions & 0 deletions .changeset/happy-seas-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"d1-orm": minor
---

This introduces breaking changes by updating to the latest `@cloudflare/workers-types@^4.20231025.0`, including compatability changes for the D1Database `exec` API. Namely, the model methods `CreateTable` and `DropTable` now return a `D1ExecResult` instead of `D1Result`.
110 changes: 58 additions & 52 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@
"devDependencies": {
"@changesets/changelog-github": "^0.4.7",
"@changesets/cli": "^2.25.0",
"@cloudflare/workers-types": "^3.17.0",
"@cloudflare/workers-types": "^4.20231025.0",
"@types/mocha": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"chai": "^4.3.6",
"chai": "^4.3.10",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-unused-imports": "^2.0.0",
"mocha": "^10.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class D1Orm implements D1Database {
return this.database.batch<T>(statements);
}

public async exec<T>(query: string): Promise<D1Result<T>> {
return this.database.exec<T>(query);
public async exec(query: string): Promise<D1ExecResult> {
return this.database.exec(query);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class Model<T extends Record<string, ModelColumn>> {
options: { strategy: "default" | "force" /* | alter */ } = {
strategy: "default",
}
): Promise<D1Result<unknown>> {
): Promise<D1ExecResult> {
const { strategy } = options;
// @ts-expect-error Alter is not yet implemented
if (strategy === "alter") {
Expand All @@ -193,7 +193,7 @@ export class Model<T extends Record<string, ModelColumn>> {
/**
* @param silent If true, will ignore the table not existing. If false, will throw an error if the table does not exist.
*/
public async DropTable(silent?: boolean): Promise<D1Result<unknown>> {
public async DropTable(silent?: boolean): Promise<D1ExecResult> {
if (silent) {
return this.D1Orm.exec(`DROP TABLE IF EXISTS ${this.tableName};`);
}
Expand Down