8000 Not working correctly with projects using Vite · Issue #469 · romeerez/orchid-orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Not working correctly with projects using Vite #469

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

Open
angelvega93 opened this issue Mar 10, 2025 · 4 comments
Open

Not working correctly with projects using Vite #469

angelvega93 opened this issue Mar 10, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@angelvega93
Copy link

Randomly or when modifying database file If the table has a relation orchid gets wrong query.

Repo with the example:
https://github.com/angelvega93/orchid-bug

Example Original query:

SELECT "id", "name", "created_at" AS "createdAt", "updated_at" AS "updatedAt" FROM "users" WHERE "users"."id" = $1 LIMIT 1

Example wrong query after modifying database.ts

SELECT "id", "name", "created_at" AS "createdAt", "updated_at" AS "updatedAt", "sessions" FROM "users" WHERE "users"."id" = $1 LIMIT 1
@romeerez
Copy link
Owner
romeerez commented Mar 23, 2025

@angelvega93 please give more details, that's not enough.

Randomly

How randomly, are you able to reproduce this by calling the same code several times, and sometimes it's broken and sometimes it's not?

or when modifying database file

Do you mean the file that calls const db = orchidORM? How do you modify it to trigger the error?

Example wrong query after modifying database.ts

How do you modify it?

Repo with the example:

It's simple and straightforward, just two tables, a simple query, I can't imagine how the query becomes broken.

@angelvega93
Copy link
Author
angelvega93 commented Mar 23, 2025

Just modify database with empty space or something to trigger a Vite HMR

Sometimes when modifying other files not related to database.ts brakes orchid maybe due to the same problem of vite HMR.

@angelvega93
Copy link
Author
angelvega93 commented Mar 25, 2025

One more thing, i don't know why but orchid seems to be really slow, even for simple queries.

const user = await db.user.find(1);

Takes around 45-50ms with orchid, while the same query with drizzle takes around 1-2ms, even when the table is completely empty.

(57.7ms) SELECT "id", "name", "created_at" AS "createdAt", "updated_at" AS "updatedAt" FROM "users" WHERE "users"."id" = $1 LIMIT 1 [1]
(46.1ms) SELECT ...
(45.1ms) SELECT ...
(51.4ms) SELECT ...
(49.2ms) SELECT ...
(47.7ms) SELECT ...
(46.8ms) SELECT ...

Any idea what could be causing the slowdown?

EDIT: Only happens with SvelteKit (Vite), blank projects takes 1-2ms as drizzle.
EDIT2: Installing the latest version of pg fix the slow queries. (pg@8.13.3 -> 8.14.1, pg-pool@3.7.1 -> 3.8.0)
EDIT3: Meanwhile you can use "vite-plugin-restart" to entirely restart vite when modifying database files.

@romeerez romeerez added the bug Something isn't working label Mar 29, 2025
@romeerez
Copy link
Owner

Thank you for finding the reasons and sharing solutions, so now we know there is a problem with HMR and it might require certain workarounds.

I'll check on HMR and pg version some day later and will update the docs for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
0