5 ms·
I would prefer 1. if it had full type safety. I’m imagining some sort of a build process that looks for any .sql files in the project and spits out .sql.d.ts in
by guntars 4y ago
I would prefer 1. if it had full type safety. I’m imagining some sort of a build process that looks for any .sql files in the project and spits out .sql.d.ts in the same directory with the input and output types according to the current schema of the database. Another nice thing about a setup like this imo would be that the .sql files would have the full support of the editor for completions and execution, unlike sql fragments in a Typescript file.
- cheeseface 4y agoSlonik comes pretty close https://github.com/gajus/slonik https://github.com/gajus/slonik. It does not inspect your DB schema, but has worked very well in our SQL-heavy architecture.
- csnweb 4y agoFor Postgres there is https://github.com/adelsz/pgtyped https://github.com/adelsz/pgtyped, sounds pretty much like what you describe?
- 8n4vidtmkvmk 4y agoI wrote a thing that connects to your live database and then dumps out d.ts files.
- piaste 4y agoF# can do this, either as part of the compilation via type providers [1] or, in a more lightweight manner, via Roslyn analyzers embedded in the editor [2]. Unsurprisingly, Haskell can also do this via Template Haskell [3], but I haven't used it. [1] https://github.com/demetrixbio/FSharp.Data.Npgsql https://github.com/demetrixbio/FSharp.Data.Npgsql [2] https://github.com/Zaid-Ajaj/Npgsql.FSharp.Analyzer https://github.com/Zaid-Ajaj/Npgsql.FSharp.Analyzer [3] https://hackage.haskell.org/package/postgresql-typed https://hackage.haskell.org/package/postgresql-typed
- shirogane86x 4y agoOn a similar note, there's also sqlx for rust [1] - and I find it extra impressive that they manage to support not only postgres, but sqlite and and mysql too. [1] https://github.com/launchbadge/sqlx https://github.com/launchbadge/sqlx