Astro + DrizzleORM => trouble
Im working with Drizzle ORM on Astro and im having some problems with continous "ETIMEDOUT". When using Prisma for the same project, I have no problem connecting to the MySQL.
Anyone has a clue as to what this could be ?
Does DrizzleORM and Astro play nice together ? Aka: will Drizzle close its connections once done ?
It could seem like its a connection-not-closing problem, as my MySQL has maximum of 10 connections, and once this error happens, it will instantly "ETIMEDOUT" for every request, until i stop/start Astro server.
49 Replies
Can you attach a log please
Drizzle should not have any issues with Astro just make sure you have the write drivers downloaded for drizzle for the correct db
(mySQL, postgresSQL, planet scale)
If you can actually see the logs of your server, you might be able to see that you're hitting a connection pool limit
Because you are just leaving them open and for whatever reason not closing them
@iukea its working until it hits the ~10 connections in total. The driver "should be correct" - as its working with MySQL (and the server is MySQL)
Each pageload takes ~4 SQL lookups, at the third page-reload it locks up.
I am not leaving the connection intentionally open - I have not seen any guides as to how to close them again (let alone, combined w Astro)
@iukea I dont have access to the MySQL server sadly. But everything "checks out" as to hitting the limit
Where is your db?
Located at a shared hosting. Prisma has no problem with it
Is Prisma running on a serverless system or running on some bare metal
Because it sounds like there's something else that's taking up this pooling and not giving it back
You can run some SQL commands to see active sessions
My guess is Prisma is just holding onto a pool
theres nothing else connecting to this db. I have two versions of my code, one iwth prisma, one with drizzl.
Both in Astro - bpth in the same project.
When i do "connection" or "poolconnection" (mysql) in Drizzl - the result is the same.
This is the error im getting from drizzl / astro.
Mmmm
Ya
This starts the first time after i get one of these:
all code runs server-side ( as in, SSR in Astro)
Okay
let me see if i can test the open connection hypothesis. 2 secs
Can you send a screenshot of where you make the connection into the db?
Is it setup like this with "connection"
If so
sure,
Try
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
const poolConnection = mysql.createPool({
host: "host",
user: "user",
database: "database",
...
});
const db = drizzle(poolConnection);
without the connection string ?
I have tried the poolConnection - its the same result. But you would like to try it with username/host separated ?
Same user and host
Shot in the dark
I can try with specifying host/user/db instead of connectionstring. 2 secs
The shot in the dark seemed to work. Let me try with connectionString instead
🫡🫡🫡🫡🫡🫡
I will have to test this quite a bit more but it seems specifiying the same content in an object, instead of in a connection string.. fixed it 😮
Working?
at the moment yes, but i will have to see it over the course of hours now
Thanks a bunch m8 ! Hope this hold ! And what a bizarre thing 1
I hope it works also.
Next-auth and Drizzle are now in kinda working also
https://github.com/mschieller/drizzle-nextauth-planetscale
GitHub
GitHub - mschieller/drizzle-nextauth-planetscale: A simple NextJS p...
A simple NextJS project showing the usage of NextAuth with Drizzle and PlanetScale, utilising prepared statement for all queries. - GitHub - mschieller/drizzle-nextauth-planetscale: A simple NextJS...
Very nice ! I like drizzl as its much closer to Laravels Eloquent.
Also you can write you queries just like you did in Prisma
You don't have to do the whole entire left join right join thing lol
He gives you two different ways to query for relationships
yearh, but i enjou the joins. the control 🙂
I am so ready
About to bring this thing into hire gear
do you know if theres anyway to get the Type-definition returned by a Drizzl-call ? So that it can be used as a parameter for a function (for example)
Like prisma has
Drizzle kit
im not sure i understand - this is more of a Prisma Studio thing right?
Drizzle kit helps you with migrations and sync
What i meant was this:
Prisma has this:
Its the Typescript-type-definition of the Payload call you are about to make
this means i can use ´PostComponentMainType` as my "requred type" in a function props for example
It generates all your types for you
npm i -D drizzle-kit
and then run
npm run introspect
On your non prod system
So for example, lets say i have this Drizzl:
This gets the comments and merges in the "user" type with a leftjoin
I make a component:
<ShowComment comment={...}>
And i want the TYPE of the prop "comment" in my component props to be exactly one of the returntypes of the above drizzl.
So i go like this:
Can Drizzlekit give me "????" ?Ya
I am sorry I am going to start driving soon but I followed this guide when I got started
its just - to me drizzlekit seems more like prisma studio and push/pull - not type-generation
Marius Espejo
YouTube
Drizzle ORM First impressions - migrations, relations, queries!
In this video we take a quick look at the drizzle ORM to see if it's good enough to replace other options like prisma, typeorm, and Kysely. We'll create a simple application to test out creating migrations, running introspection, creating queries, and using relations. If you're looking for an orm for database queries that has very good typescrip...
Also they have zod support or something idk
https://orm.drizzle.team/docs/zod
Usage – DrizzleORM
Drizzle ORM | %s
yearh, but sadly that doesnt solve the problem :/ it deosnt take relations into account
Ast thing I got
I need to go
I will be back later
yearh, tahts just declaring the relations though - it wont give you any way to define a specific type that has been returned by the DB.table.select.leftjoin
Its the return type that I / we need a way to get. This one: it changes with the SQL sentence, and "should be possible to get" from somewhere. Thats what Prisma can do:
The above example is a type containing SOME fields from "comment" type and SOME fields of "user" type - in a mixed type / result from the database.
In prisma you can do
commentGetPayload< your object that you pass into prisma db call without actually calling the database >
and that will return a type
that you can use to Type your parameters.
Problem is, if you take Drizzle results and parse it into a component, when you use it in the component the type will by definition be "lost", as theres no relation from the component to where you use the component.
(and it will have to be an "any" type, or you have to make a 1:1 copy type of whatever you return from the drizzl db.table.select.leftjoin)I will look into it more and ask
Great - let me know if the usecase makes sense. But its super type-important 🙂