Boilerplate generator for gorm
go install github.com/myyrakle/gormery@v0.2.2
The .gormery.yaml
file must exist in the project root path.
Here is an example of a config file.
basedir: example
output-suffix: "_gorm.go"
runner-path: "cmd/gormery"
features:
- SLICE
It means that all files in the example directory will be read, and the output file will be created with the name "*_gorm.go".
Usage is very simple. Just run the following command in your project root path:
gormery
gormery only generates structures with // @Gorm
comments. t reads structures and fields and produces a list of methods and constants.
If you have a struct like
// @Gorm
type Person struct {
ID string
Name string
}
mongery produces a list of constants like this:
func (t Person) TableName() string {
return "people"
}
func (t Person) StructName() string {
return "Person"
}
const Person_ID = "id"
const Person_Name = "name"
func (t Person) Columns() []string {
return []string{
Person_ID,
Person_Name,
}
}
features:
- SLICE
If you enable Slice among the features flags, it creates a basic boilerplate for Slice.
It is as follows:
type PersonSoManies []PersonSoMany
func (t PersonSoManies) Len() int {
return len(t)
}
func (t PersonSoManies) IsEmpty() bool {
return len(t) == 0
}
func (t PersonSoManies) First() PersonSoMany {
if t.IsEmpty() {
return PersonSoMany{}
}
return t[0]
}