Next.js autocomplete with Drizzle
Unanswered
Mackenzie River Husky posted this in #help-forum
Mackenzie River HuskyOP
Hi everyone!
I have a question regarding Next.js with Drizzle. I previously used Prisma, but I've seen in several places that Drizzle is faster and more efficient with queries. However, I feel like I'm doing something wrong or is it really this much of a hassle to write?
There's a lot of boilerplate initially, but my problem is that you really have to import the tables one by one for a query? And the autocomplete doesn't work with the tables, also it brings up the window (CTRL + Space) very slowly. What's even more annoying is that for a select, it doesn't suggest the column names within the table with CTRL + Space, so I have to write these out myself, which means there's no type safety.
Is something misconfigured on my end, or is this the usual way to use it?
Additionally, what I find strange is that the whole thing is quite new, but already almost every tutorial is outdated because the syntax has changed as far as I can see.
Thank you in advance!
I have a question regarding Next.js with Drizzle. I previously used Prisma, but I've seen in several places that Drizzle is faster and more efficient with queries. However, I feel like I'm doing something wrong or is it really this much of a hassle to write?
There's a lot of boilerplate initially, but my problem is that you really have to import the tables one by one for a query? And the autocomplete doesn't work with the tables, also it brings up the window (CTRL + Space) very slowly. What's even more annoying is that for a select, it doesn't suggest the column names within the table with CTRL + Space, so I have to write these out myself, which means there's no type safety.
Is something misconfigured on my end, or is this the usual way to use it?
Additionally, what I find strange is that the whole thing is quite new, but already almost every tutorial is outdated because the syntax has changed as far as I can see.
Thank you in advance!
12 Replies
@Mackenzie River Husky Hi everyone!
I have a question regarding Next.js with Drizzle. I previously used Prisma, but I've seen in several places that Drizzle is faster and more efficient with queries. However, I feel like I'm doing something wrong or is it really this much of a hassle to write?
There's a lot of boilerplate initially, but my problem is that you really have to import the tables one by one for a query? And the autocomplete doesn't work with the tables, also it brings up the window (CTRL + Space) very slowly. What's even more annoying is that for a select, it doesn't suggest the column names within the table with CTRL + Space, so I have to write these out myself, which means there's no type safety.
Is something misconfigured on my end, or is this the usual way to use it?
Additionally, what I find strange is that the whole thing is quite new, but already almost every tutorial is outdated because the syntax has changed as far as I can see.
Thank you in advance!
yea, with drizzle you need to write more, that's true. With auto complete I never had any problems. Sometimes the importing first sucks, but that's fine. I hope, that this will be better with the next version they are working on. The will provide way better stuff than the current version and of course also better and more efficent code, to write less, but keep type safety
Mackenzie River HuskyOP
Thanks your for your fast response!
Based on the feedback and some screenshots, do you have any tips on why the autocomplete for columns might not be working? Also, could you confirm if my queries are written correctly?
Any suggestions or corrections would be greatly appreciated!
Based on the feedback and some screenshots, do you have any tips on why the autocomplete for columns might not be working? Also, could you confirm if my queries are written correctly?
Any suggestions or corrections would be greatly appreciated!
If I hover over the users table in the "from(user)" part of the code, I'm seeing this:
@Mackenzie River Husky If I hover over the users table in the "from(user)" part of the code, I'm seeing this:
yes, that completely normal, because that's how drizzle structure their tables. They structure it not as simple json, as you can see (and that's good if you ask me)
why the autocomplete for columns might not be working?If you mean the part:
.seclect({HERE})That's because drizzle don't know how you want to name your return values. You should be typesafe after you entered your variable name:
.seclect({variableName: users.HERE-IS-TYPESAFE})Also, could you confirm if my queries are written correctly?You query looks good for me. However I don't know anything about so project. I like to use
db.query.table.... to query specific parts of dataMackenzie River HuskyOP
Actually, there's nothing special about my code. I just started following a simple tutorial where I check if the user exists during login.
For some reason, the db.query.table.... isn't working for me... it brings up what's shown in the screenshot. Even when I type in the users table, TypeScript complains that I haven't provided the database type. Is there something wrong with my config files? I also sent those in the first post.
I would be very grateful if you could take a look at them.
For some reason, the db.query.table.... isn't working for me... it brings up what's shown in the screenshot. Even when I type in the users table, TypeScript complains that I haven't provided the database type. Is there something wrong with my config files? I also sent those in the first post.
I would be very grateful if you could take a look at them.
I thought what you're writing, the db.query.table, is the old syntax.
@Mackenzie River Husky I thought what you're writing, the db.query.table, is the old syntax.
Nah, dB query is the new syntax … something is wrong there…
@Mackenzie River Husky Actually, there's nothing special about my code. I just started following a simple tutorial where I check if the user exists during login.
For some reason, the db.query.table.... isn't working for me... it brings up what's shown in the screenshot. Even when I type in the users table, TypeScript complains that I haven't provided the database type. Is there something wrong with my config files? I also sent those in the first post.
I would be very grateful if you could take a look at them.
I just rechecked with my code and you missing the schema inside your init. Put your schema here: (see attached). Like this: (see attached)
As you can see there is tab completion: (see attached). And also table completion for the columns: (see attached)
Mackenzie River HuskyOP
It seems to be resolved, many thanks for the help. Now TypeScript autocomplete is working correctly. However, it’s strange that this is incorrect in the documentation. I mean for this: https://orm.drizzle.team/learn/tutorials/drizzle-with-neon
I’ll paste here what I modified in case anyone else is struggling with this problem.
I’ll paste here what I modified in case anyone else is struggling with this problem.