dbgen

command
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2020 License: BSD-2-Clause Imports: 17 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL