@b0rk I have a mid-sized project in Go which statically types *all* SQL and *som...
evana @evana@hachyderm.io
@b0rk I have a mid-sized project in Go which statically types *all* SQL and *some* HTML (to be fair, it's mostly an API, so the HTML parts are limited).
We use sqlc for the static SQL typing, which seems to work quite well, though not quite as magical as Django migrations. Basically, sqlc needs to know your schema (which we maintain as a series of migration files for postgres) and a set of queries that you want to run, with appropriate substitutions. sqlc will then generate source files defining methods with appropriate input and output arguments (of the correct type, including nullability). We check in those files mostly so we can simplify the normal build process, but they are just standard generated go files that leverage the database's parameterized query tooling.
If you go to change the schema or a query (for example, introducing nullability to a field), sqlc will generate differently-typed arguments, and the compiler will tell you where you need to go fix things.
Another nice-ish thing about having methods for these queries is that you can mock them, though sometimes that gets taken too far.
For HTML, we use go's html/template, which does escaping. We also have some markdown / text templating that is user-configured alongside the input; that uses JSON objects and is effectively dynamically typed. We avoid serving that across trust domains, though.