Documentation
¶
Overview ¶
dbgen is a tool to automate the creation of create/update/delete methods that satisfy the github.com/paulstuart/dbobj.DBObject interface.
For example, given this snippet,
package dbobjs
type User struct {
ID int64 `sql:"id" key:"true" table:"users"`
Username string `sql:"username"`
First string `sql:"firstname"`
Last string `sql:"lastname"`
Email string `sql:"email"`
Role int `sql:"role"`
UserID int64 `sql:"userid" audit:"user"`
Modified time.Time `sql:"modified" audit:"time"`
Created time.Time `sql:"created" update="false"
}
running this command
dbgen
in the same directory will create the file db_generated.go, in package dbobjs, containing the definition:
Typically this process would be run using go generate, like this:
//go:generate dbgen
The -type flag accepts a comma-separated list of types so a single run can generate methods for multiple types. The default output file is db_generated.go, where t is the lower-cased name of the first type listed. It can be overridden with the -output flag.
Click to show internal directories.
Click to hide internal directories.