How to debug Drizzle queries
I'm executing an insert on a table, I'm gettin no errors, and yet the data is not being saved to the database.
Just curious how I am supposed to debug stuff like this since I have no idea why it isn't working.
26 Replies
Trying to log my queries would be my first step: https://orm.drizzle.team/docs/goodies#logging
Goodies – DrizzleORM
Drizzle ORM | %s
Maybe a dumb question, but do you await this query?
I've tried both awaited and unawaited, doesn't seem to make a difference. I'm sure you saw my other post about vscode telling me that async doesn't make a difference
You can see the little underline under "await". When hovered it says
'await' has no effect on the type of this expression.ts(80007)
what if you also await the db.insert?
A query has to be awaited or returned (and then awaited on function call)
without await, it is a query builder, waiting to be executed or awaited
Executing with await does nothing either
Simpler example
It doesn't appear to be executing in the logger either. Reads work fine enough
seems to be legit code 🤔
is it typescript or js ?
TypeScript
The select you are seeing in the above occurs when the page reloads
So the insert isn't even running
This might be a SvelteKit issue. I have a project that works perfectly fine and it doesn't have the async warning when using await.
I don’t know anything about svelte 🥶
I'm looking through and it seems exactly the same. The only difference is that I'm using Turso in the new project
a tsconfig issue?
if I await a query, it works fine. But awaiting an insert doesn't do anything
that’s what trouble me
the code you show seems 100% correct
Is there something possibly wrong with the libsql connector?
I think the driver would throw something. Here it looks like the query is not executed.
can you console log the whole query line?
what vscode is suggesting after values(...). ?
Sorry for all of this, trying to dig deeper as I can lol
Do I have to "run" the insert?
oml if I use
.run()
at the end it runs
I don't have to do that for the other drivers? Extremely strange that I have to do that for libsql@Andrew Sherman Hey, sorry to ping you. Is it expected?
Yes, it’s expected for SQLite, but we will release a new version, where SQLite api will be the same as other dialects
I guess tomorrow or a few days
We just fixing the docs for that
It’s already done
So, soon in latest
wonderful. i think we have tried everything here haha
Yeah, sorry for that
Our bad for not showing that in docs
Ah, ok. In the future I would recommend updating the docs with warnings or something. I love what you guys are doing, but I spent the last hour and a half on this.
With everything we ask of them, they are overbooked 😅. It becomes better every day, I remember when the doc was only a readme 🥶
Yeah, I don't want to be too needy, but if something is being worked on or isn't stable it would be nice to know. I'm sure they are aware the value that good docs has in the fast moving web space. It's not like I'm going to stop using Drizzle though. I couldn't really stand prisma so its a big improvement