About:
-
This tool has been adapted from Genna - https://github.com/dizzyfool/genna which has been made for go-pg package. I think it will be cool to have same CLI but for Bun which is new evolution of
go-pg
-
Although this CLI is targeted for Bun, you should be aware that it's still compatible with Postgres only.
-
I've done a lot of plain code replacements: current tests are fine, but I haven't managed cases with multiple FK's, composite FK's. I do know that this tool needs to manage DEFAULT values e.g.
default:'SOME DEFAULT FUNCTION'
also, but this needs more affort (pull requests are welcome).
Requirements:
- bun
- your PostgreSQL database
In most of the cases Bun [Postgres driver] models represent database's tables and relations. Bungen's main goal is to prepare those models by reading detailed information about PostrgeSQL database. The result should be several files with ready to use structs with Bun ORM package.
- Install
go get github.com/LdDl/bungen && go install github.com/LdDl/bungen@latest
- Read though help
bungen -h
Currently bungen support 3 generators:
- model, that generates basic Bun [Postgres driver] model (with provided
-q
and-z
flags it is possible to create simpleSELECT *
functions) - model-named, same as basic but with named structs for columns and tables (author: @Dionid)
- search, that generates search structs for basic model
- validation, that generates validate functions for basic model
Examples located in each generator
- I am thankful to Genna and its creator @dizzyfool. Its contributors should be mentioned also. This CLI saved a lot of time for me in the past.
- Big shoutouts to Bun creators for great ORM package for Golang