Skip to content

Commit

Permalink
feat: update to latest D1 Database interface (#71)
Browse files Browse the repository at this point in the history
* chore: bump @cloudflare/workers-types, chai

* refactor: expect `D1ExecResult` over `D1Result` for exec

* chore: add changeset
  • Loading branch information
dtbuchholz authored Oct 29, 2023
1 parent 2e8dac4 commit 5c168e9
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 58 deletions.
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

0 comments on commit 5c168e9

Please sign in to comment.