I've seen your squid project as well, and I'm glad to see someone exploring this direction. 😀
Running static analysis on the SQL bits is interesting - but appears to miss out on refactoring safety? I believe there is a much simpler and refactoring-safe way to approach this - have a look at this old thing I built in PHP some years back:
That is, to use static references for all table and column symbols, e.g. interpolating schema/column objects and values into template literals:
sql`SELECT * FROM ${user} WHERE ${user.id} = ${id}`
This approach would work much better with JS/TS than it did with PHP, since user and user.id would have types that the sql function can recognize. (in PHP the string interpolation happens before the call, which creates some corner cases and inconsistencies for e.g. INSERT statements in my library.)
Now you can rename user or user.id (with TS at least) and have automatic refactoring. You also get errors highlighted (by TS) for example after removing a column. Running static analysis on the SQL queries is probably much less necessary then, and the whole thing could be quite a bit simpler?
I know some users are averse to interpolation-heavy syntax - personally, considering how much this pays back in terms of safety and refactoring, I don't mind at all.
Prisma, TypeORM and Sequelize just don't do it for me - they're either too complex or too removed from SQL. I hope the idea of leveraging string interpolation catches on more widely in the future.
Cheers. 🙂
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I've seen your squid project as well, and I'm glad to see someone exploring this direction. 😀
Running static analysis on the SQL bits is interesting - but appears to miss out on refactoring safety? I believe there is a much simpler and refactoring-safe way to approach this - have a look at this old thing I built in PHP some years back:
github.com/mindplay-dk/sql#select-...
That is, to use static references for all table and column symbols, e.g. interpolating schema/column objects and values into template literals:
This approach would work much better with JS/TS than it did with PHP, since
user
anduser.id
would have types that thesql
function can recognize. (in PHP the string interpolation happens before the call, which creates some corner cases and inconsistencies for e.g.INSERT
statements in my library.)Now you can rename
user
oruser.id
(with TS at least) and have automatic refactoring. You also get errors highlighted (by TS) for example after removing a column. Running static analysis on the SQL queries is probably much less necessary then, and the whole thing could be quite a bit simpler?I know some users are averse to interpolation-heavy syntax - personally, considering how much this pays back in terms of safety and refactoring, I don't mind at all.
Prisma, TypeORM and Sequelize just don't do it for me - they're either too complex or too removed from SQL. I hope the idea of leveraging string interpolation catches on more widely in the future.
Cheers. 🙂