Documentation ¶
Overview ¶
go-sqlx Generates Go code using a package as a generic template that implements sqlx. Given the StructName of a Struct type T go-sqlx will create a new self-contained Go source file and rewrite T's "db" tag of struct field The file is created in the same package and directory as the package that defines T. It has helpful defaults designed for use with go generate.
For example, given this snippet,
running this command
go-sqlx -type=Pill
in the same directory will create the file pill_sqlx.go, in package painkiller, containing a definition of helper for sqlx
Typically this process would be run using go generate, like this:
//go:generate go-sqlx -type=Pill //go:generate go-sqlx -type=Pill --linecomment //go:generate go-sqlx -type=Pill --linecomment --with-dao
With no arguments, it processes the package in the current directory. Otherwise, the arguments must trimmedStructName a single directory holding a Go package or a set of Go source files that represent a single Go package.
The -type flag accepts a comma-separated list of types so a single run can generate methods for multiple types. The default flagOutput file is t_string.go, where t is the lower-cased trimmedStructName of the first type listed. It can be overridden with the -flagOutput flag.