dbgen

command
v0.0.0-...-13e7ea3 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: BSD-2-Clause Imports: 19 Imported by: 0

Documentation

Overview

dbgen is a tool to automate the creation of CRUD methods (create/update/delete) that satisfy the DBObject interface in github.com/paulstuart/rqlobj.

For example, given this snippet,

package dbobjs
type User struct {
	ID       int64		`sql:"id,key" 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