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

Added executeRaw() #482

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Added executeRaw() #482

wants to merge 1 commit into from

Conversation

Chriztiaan
Copy link
Contributor

@Chriztiaan Chriztiaan commented Jan 28, 2025

Description

Currently duplicate column names in a query result are overwritten with only the last column being the one return. This causes issues with join queries (a simple case is where multiple id columns are returned) and is more apparent when doing joins with one of the ORM drivers (Kysely/Drizzle). This issue is covered by the newly added tests.

This PR introduces executeRaw which processes the sqlite3 results differently and allows the ORM driver to correctly map the resulting columns.

An existing approach for Drizzle-orm packages can be seen here:
https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/op-sqlite/session.ts#L165
https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/better-sqlite3/session.ts#L156

To be done

  • Update RNQS to expose an executeRaw member
  • Test RNQS
  • Test OPSQLite's executeRaw implementation
  • Test web with/without workers in a browser
  • Unit tests for Kysely joins

Workaround

For Drizzle users using joins the following example shows how to side-step the problem in the interim:

wait db
      .select({ id: drizzleUsers.id, postsId: sql`"posts"."id"`.as('postsId') }) // or postsId: drizzlePosts.id.getSQL().as('postsId')
      .from(drizzleUsers)
      .leftJoin(drizzlePosts, eq(drizzleUsers.id, drizzlePosts.user_id));

Copy link

changeset-bot bot commented Jan 28, 2025

⚠️ No Changeset found

Latest commit: 6877d2c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Successfully merging this pull request may close these issues.

1 participant