Using cache with drizzle
How exactly would I use
cache
with the select
from drizzle? if it was just the method it would be simple, but it returns from
that returns where
and there's all the other methods. How the hell am I supposed to do this?21 Replies
React query with keys and no refetch
Any new combination would be fetch on demand
Any old combination would be csched already and there would be no need to fetch again
i'm fetching on the server
with db.select
Data Fetching: Caching
Learn about caching routes in Next.js.
That's for prisma
I know how to use cache
I don't know how to use cache with the select method from drizzle
what does that mean?
is it not the exact same thing
I'm making a utility method
I mean select in general
Not just the user ID or something like that
you want to cache every possible select call?
I dont think you can, or would really even want to
With prisma I could just do
cache(prisma.type.thing)
Not necessarily allcan you explain what you were doing with prisma
with an example
It would cover every single findFirst for the type
I can cover every single from manually
https://orm.drizzle.team/docs/rqb
just use relational queries and do the same thing
Relational queries – DrizzleORM
Drizzle ORM | %s
But the problem is the select and where methods
I'll try
Brb
i'm using lucia-auth and i'm not sure relations are supported
heres the thing though
you should only be caching one set query at a time
once you start adding different where and limit whatever things
its just a completely different query
Solution
caching everything under one mega function is a way to do it
but probably not the best
---
could you send some examples of the kinds of queries youll be writing you want cached
You're right
I should male one cache function for each page
I'm so dumb
@.perry. are you using planetscale serverless driver with drizzle
i'm using neondb
and the pg driver because it's what lucia-auth supports
ive been rereading the next docs and playing around with a test project
my mental mode for
cache
was a bit off
its only purpose is to dedupe calls to the same underlying code when called from multiple components in a render step
so for querying a database client its only necessary if you are making the exact same query (like every single aspect) the same in multiple placesi'm doing that