sqrible
sqrible copied to clipboard
Generates Go code that matches your Postgres tables
Problematic
Sqrible came out of the frustation of working with pgx and sqlx.
I had to buid a crappy bridge which led to nowhere and this did not solve the problem that for every request sqlxhas to use Golang's reflection to map query results to struct fields.
This did not sound right.
The other option is to map each field manually but that's tedious and error prone.
So the solution is to generate go code that would do everything automatically.
The advantages are:
- I no longer need sqlx and thus limit reflection usage to pgx
- With a set of template I can generate the code I need and update it easily with a few template changes
How does it work ?
Sqrible scans informations about a given table, reads what you configured for this table in a yaml config file and output the generated code you built with the provided template.
Building
make deps build
Usage
./bin/sqrible --help
Usage of ./bin/sqrible:
-c string
/path/to/config/file.yaml
-d string
template dir
-t string
table name
Examples
Have a look in the examples
directory which contains one simple template
which showcases informations sqrible has about a table. The advanced
example
showcases a more real life usage.
Demo
Other projects in this field
FAQ
Do you plan to support other DBMSes ?
No. I only need Postgres support and do not plan to provide any support for MySQL, Oracle ... Have at look at xo ;)