It looks like I’m going to need to build an API th...
# random
r
It looks like I’m going to need to build an API that allows a user to perform multi-field filtering and sorting against a MySQL (PlanetScale) table. Rather than cook up those queries myself I’m considering using an ORM or equivalent tool. I’m not familiar with what’s good in that space but I’ve read in here about people using Kysely, TypeORM, Prisma and probably others. What do you guys recommend I take a look at?
I should say, the table in question is likely to be very wide, possibly 40 or 50 columns
t
the problem you're describing is very familiar to me
I haven't done it yet but I wanted to try to do this with kysely since it's easy to progressively / conditionally build a query
and it's still very close to be a normal SQL query and not too abstracted
basically you want to dynamically build a sql string, but operating on the string level is a pain. kysely lets you operate one level above so you can do things like conditionally add where or sort clauses
r
Cool - that’s what I was thinking browsing their docs, much easier to chain a bunch of .
where()
and .
orderBy()
clauses, like you say, than hacking around with building strings. I’ll probably give that a go
s
I worked with Kysely last week and had a good experience. My DB is RDS Postgres (non-serverless) and the Postgres dialect worked great
My table has ~350-ish tables, which could be a challenge when using a tool like Kysely where you define each table as an interface. I found rmp135, which generated the types directly from the DB
k
@Seth Geoghegan nice tool 😉 Btw, if you ever have to nicely document a DB, I found Schemaspy very useful. It builds relationship diagrams, show procedures etc.
s
Very nice! I used. tool like that on this database, and the result was hilarious
k
Schema spy worked very well for me with Postgres
Copy code
java -jar schemaspy.jar -t pgsql11 -dp [path_to_/postgresql.jar] -db [db_name] -host [db_host] -port 5432 -s [schema] -u [user] -p [password] -vizjs -o [outfile] -imageformat svg
one problem with visjs though is the memory consumption. On github for schemaspy they describe an approach to use an external graphviz instance to handle huge DBs
t
Rmp135 is cool maybe we'll integrate with that
s
it worked first try for me 👍
would be nice to automate so it runs after DB migrations
t
@Seth Geoghegan officially attempting to integrate rmp135 into our RDS construct. Needs some tweaking so it can talk to the data-api but the idea is to have it run whenever you apply a migration
s
Awesome! That's a cool feature
t
@Seth Geoghegan did you manually join all the generated interface into a Database interface? or was there a way in sql-ts to do that
s
I manually created the interface, didn't look into automating that part yet
t
gotcha, yeah dont' think it works out of the box with sql-ts, I wrote a quick thing to do that
the other issue is computed columns like
created_at
- kysely has a special type you have to use so not sure how I'm gonna deal with that