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

all() with Cloudflare D1 returns full D1Result #142

Open
micheh opened this issue Jan 5, 2025 · 1 comment
Open

all() with Cloudflare D1 returns full D1Result #142

micheh opened this issue Jan 5, 2025 · 1 comment

Comments

@micheh
Copy link

micheh commented Jan 5, 2025

Environment

Cloudflare D1

Reproduction

const rows = await db
      .prepare(`SELECT * FROM Customers`)
      .all();

Describe the bug

When using the all() method with Cloudflare D1, the full D1Result object is returned:

{
  success: boolean, // true if the operation was successful, false otherwise
  meta: {
    served_by: string // the version of Cloudflare's backend Worker that returned the result
    duration: number, // the duration of the SQL query execution only, in milliseconds
    changes: number, // the number of changes made to the database
    last_row_id: number, // the last inserted row ID, only applies when the table is defined without the `WITHOUT ROWID` option
    changed_db: boolean, // true if something on the database was changed
    size_after: number, // the size of the database after the query is successfully applied
    rows_read: number, // the number of rows read (scanned) by this query
    rows_written: number // the number of rows written by this query
  }
  results: array | null, // [] if empty, or null if it does not apply
}

https://developers.cloudflare.com/d1/worker-api/return-object/#d1result

The method should probably only return the content of the results attribute without the success and meta attributes. The other two methods run and get return the expected result.

Additional context

No response

Logs

No response

@amandesai01
Copy link
Contributor

amandesai01 commented Jan 9, 2025

Looks like a valid point. I also don't find tests for d1 (which would have caught this). Will triage first and raise a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants