Middleware triggering edge runtime breaking ANY database
Unanswered
Toyger posted this in #help-forum
ToygerOP
when I add middleware doesnt matter what it does it breaks any database I tried mysql, postgres, mongo, mongodb, prisma and drizzle
20 Replies
ToygerOP
ive spent like 10 hours trying to find a solution trying multiple databases/clients
I want middleware but also a database 

@Toyger ive spent like 10 hours trying to find a solution trying multiple databases/clients
Sloth bear
I'm using middleware here with drizzle and sqlite and it works fine
Your database must support the edge runtime tho since middlewares uses the edge runtime since cloudflare d1 works on edge runtime my application works
@Sloth bear Your database must support the edge runtime tho since middlewares uses the edge runtime since cloudflare d1 works on edge runtime my application works
ToygerOP
Barely any database supports that
Mongo Nuh uh
Postgres Nuh uh
Mysql Nuh uh
Postgres Nuh uh
Mysql Nuh uh
Sloth bear
Do you mean a postgres running on your machine yes that doesn't support it
But services like Neon gives you a postgres database that works on the edge
I'm not sure but I think Sqlite should work locally too
But services like Neon gives you a postgres database that works on the edge
I'm not sure but I think Sqlite should work locally too
ToygerOP
isn’t neon paid
Sloth bear
Or you can just create an API route that does what you want and make a fetch request from your middleware to that API route
holy shit ur genius
thanks
I’ll try later
I can’t rn

Asian black bear
It's not a problem of the databases and rather their drivers. Some offer serverless drivers working on Edge which work using conventional fetch requests to a specific API allowing access to the database.
@Sloth bear Or you can just create an API route that does what you want and make a fetch request from your middleware to that API route
ToygerOP
The thing is whenever I remove middleware.ts it’s fine but when I add it and it does nothing like its empty and returns next then it errors cuz middleware requires edge runtime
so I gotta switch databases again I guess
😭