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

astro:db: db.run queries are giving different responses from Astro Studio and from local files #10970

Closed
1 task done
timsexperiments opened this issue May 8, 2024 · 1 comment · Fixed by #11091
Closed
1 task done
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@timsexperiments
Copy link

Astro Info

Astro                    v4.7.1
Node                     v22.0.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             astro:db
                         @astrojs/db/file-url
                         @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When running queries with db.run, the result returned from the query differs on file and Astro DB databases. When running a query to a file database (local / using the ASTRO_DATABASE_FILE env var) the query rows are properly aliased with both the index and the alias for the selected column.

Another observation I have noticed is that with the file-based database response, the result.rows values are not iterable where they are iterable from the Astro Studio version. This means that destructuring a row by [first, second, ...] = result.rows[0] will not work on file-based database but will work with an Astro Studio DB.

Assuming the following code was run:

import { db, sql } from  'astro:db';

const result = db.run(sql`SELECT 1 as value`);

The following is an example of what works with the different configurations:

Example Code Astro Studio Database value Result File-Based Databasevalue Result
Access through alias const { value } = result undefined 1
Access through index const { 0: value } = result 1 1
Access through iterable const [value] = result 1 Throws: TypeError: object is not iterable (cannot read property

What's the expected result?

I would expect:

  1. The values are to be accessible through both the alias and the index, no matter what type of database is being used through the Astro DB API.

  2. Either both results to be iterable or neither to be iterable.

Link to Minimal Reproducible Example

https://github.com/timsexperiments/astro-sql-file-vs-remote

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label May 8, 2024
@matthewp matthewp added - P4: important Violate documented behavior or significantly impacts performance (priority) - P3: minor bug An edge case that only affects very specific usage (priority) and removed - P4: important Violate documented behavior or significantly impacts performance (priority) needs triage Issue needs to be triaged labels May 8, 2024
@matthewp
Copy link
Contributor

matthewp commented May 8, 2024

Definitely odd and not something I would expect. Thanks for letting us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants