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
rphlmr ⚡
rphlmr ⚡16mo ago
Trying to log my queries would be my first step: https://orm.drizzle.team/docs/goodies#logging
Goodies – DrizzleORM
Drizzle ORM | %s
rphlmr ⚡
rphlmr ⚡16mo ago
Maybe a dumb question, but do you await this query?
SteveS
SteveSOP16mo ago
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
SteveS
SteveSOP16mo ago
No description
SteveS
SteveSOP16mo ago
You can see the little underline under "await". When hovered it says 'await' has no effect on the type of this expression.ts(80007)
rphlmr ⚡
rphlmr ⚡16mo ago
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
SteveS
SteveSOP16mo ago
Executing with await does nothing either
SteveS
SteveSOP16mo ago
Simpler example
No description
SteveS
SteveSOP16mo ago
It doesn't appear to be executing in the logger either. Reads work fine enough
rphlmr ⚡
rphlmr ⚡16mo ago
seems to be legit code 🤔 is it typescript or js ?
SteveS
SteveSOP16mo ago
anything <-- this is logged when the action is run
Query: select "id", "user_id", "first_name", "last_name", "address", "phone", "linkedin_url", "statement" from "personal_information" "personalInformationTable" where "personalInformationTable"."user_id" = ? limit ? -- params: ["3zx69w1e8w6ghkz", 1]
{
id: 1,
userId: '3zx69w1e8w6ghkz',
firstName: 'steve',
lastName: null,
address: null,
phone: null,
linkedin_url: null,
statement: null
}
anything <-- this is logged when the action is run
Query: select "id", "user_id", "first_name", "last_name", "address", "phone", "linkedin_url", "statement" from "personal_information" "personalInformationTable" where "personalInformationTable"."user_id" = ? limit ? -- params: ["3zx69w1e8w6ghkz", 1]
{
id: 1,
userId: '3zx69w1e8w6ghkz',
firstName: 'steve',
lastName: null,
address: null,
phone: null,
linkedin_url: null,
statement: null
}
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.
rphlmr ⚡
rphlmr ⚡16mo ago
I don’t know anything about svelte 🥶
SteveS
SteveSOP16mo ago
I'm looking through and it seems exactly the same. The only difference is that I'm using Turso in the new project
rphlmr ⚡
rphlmr ⚡16mo ago
a tsconfig issue?
SteveS
SteveSOP16mo ago
if I await a query, it works fine. But awaiting an insert doesn't do anything
rphlmr ⚡
rphlmr ⚡16mo ago
that’s what trouble me the code you show seems 100% correct
SteveS
SteveSOP16mo ago
Is there something possibly wrong with the libsql connector?
rphlmr ⚡
rphlmr ⚡16mo ago
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
SteveS
SteveSOP16mo ago
Do I have to "run" the insert?
SQLiteInsert {
session: LibSQLSession {
dialect: SQLiteAsyncDialect {},
client: HttpClient { protocol: 'http' },
schema: { fullSchema: [Object], schema: [Object], tableNamesMap: [Object] },
options: { logger: [DefaultLogger] },
tx: undefined,
logger: DefaultLogger { writer: ConsoleLogWriter {} }
},
dialect: SQLiteAsyncDialect {},
config: {
table: SQLiteTable {
id: [SQLiteInteger],
userId: [SQLiteText],
firstName: [SQLiteText],
lastName: [SQLiteText],
address: [SQLiteText],
phone: [SQLiteText],
linkedin_url: [SQLiteText],
statement: [SQLiteText],
[Symbol(drizzle:Name)]: 'personal_information',
[Symbol(drizzle:OriginalName)]: 'personal_information',
[Symbol(drizzle:Schema)]: undefined,
[Symbol(drizzle:Columns)]: [Object],
[Symbol(drizzle:BaseName)]: 'personal_information',
[Symbol(drizzle:IsAlias)]: false,
[Symbol(drizzle:ExtraConfigBuilder)]: undefined,
[Symbol(drizzle:IsDrizzleTable)]: true,
[Symbol(drizzle:SQLiteInlineForeignKeys)]: [Array]
},
values: [ [Object] ]
},
run: [Function: run],
all: [Function: all],
get: [Function: get],
values: [Function: values]
}
SQLiteInsert {
session: LibSQLSession {
dialect: SQLiteAsyncDialect {},
client: HttpClient { protocol: 'http' },
schema: { fullSchema: [Object], schema: [Object], tableNamesMap: [Object] },
options: { logger: [DefaultLogger] },
tx: undefined,
logger: DefaultLogger { writer: ConsoleLogWriter {} }
},
dialect: SQLiteAsyncDialect {},
config: {
table: SQLiteTable {
id: [SQLiteInteger],
userId: [SQLiteText],
firstName: [SQLiteText],
lastName: [SQLiteText],
address: [SQLiteText],
phone: [SQLiteText],
linkedin_url: [SQLiteText],
statement: [SQLiteText],
[Symbol(drizzle:Name)]: 'personal_information',
[Symbol(drizzle:OriginalName)]: 'personal_information',
[Symbol(drizzle:Schema)]: undefined,
[Symbol(drizzle:Columns)]: [Object],
[Symbol(drizzle:BaseName)]: 'personal_information',
[Symbol(drizzle:IsAlias)]: false,
[Symbol(drizzle:ExtraConfigBuilder)]: undefined,
[Symbol(drizzle:IsDrizzleTable)]: true,
[Symbol(drizzle:SQLiteInlineForeignKeys)]: [Array]
},
values: [ [Object] ]
},
run: [Function: run],
all: [Function: all],
get: [Function: get],
values: [Function: values]
}
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
rphlmr ⚡
rphlmr ⚡16mo ago
@Andrew Sherman Hey, sorry to ping you. Is it expected?
Andrii Sherman
Andrii Sherman16mo ago
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
rphlmr ⚡
rphlmr ⚡16mo ago
wonderful. i think we have tried everything here haha
Andrii Sherman
Andrii Sherman16mo ago
Yeah, sorry for that Our bad for not showing that in docs
SteveS
SteveSOP16mo ago
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.
rphlmr ⚡
rphlmr ⚡16mo ago
With everything we ask of them, they are overbooked 😅. It becomes better every day, I remember when the doc was only a readme 🥶
SteveS
SteveSOP16mo ago
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
Want results from more Discord servers?
Add your server