SQL Type Safety
The cluster discusses type safety in SQL, focusing on static type checking of queries at compile time using tools like pgtyped and sqlx, and contrasts strict databases like Postgres with flexible ones like SQLite.
Activity Over Time
Top Contributors
Keywords
Sample Comments
If type safety is so great, why isn’t sql statically type checked
Have you tried pgtyped? I'm in love with it: it allows us check SQL queries at compile times and statically type them.
strong typing for arbitrary sql queries is actually really nice and this is much better than stuff like sequelize or typeorm which seem sadistic in comparison
Would be nice to add types to SQL instead of adding json objects as sql
SQL (at least in Postgres) is already type safe.
I can imagine what would be/is valuable is type checked embedded SQL queries.
Very much agree with this. I really like how sqlx (on rust) does it. You just write normal SQL queries, and it will check and validate the types against your db. Best of both worlds.
You mean it's impossible to have compile time type safety of sql queries, and that the compiler can't tell the difference between an SQL string and any other string? You're wrong.http://underscore.io/blog/posts/2015/05/28/typechecking-sql....
It is quite statically typed, look at the examples. You might be thinking of the stringly-typed version, but it can generate classes from DB inspection and use columns and whatnot with its respective type throughout a query, failing to compile when a group by value is incorrect! It can’t verify everything what a SQL engine can of course, but it is quite remarkable in my opinion.
I wonder what a statically typed SQL would look like.