Documentation ¶
Index ¶
- Constants
- Variables
- func Criteria(pkg *ast.Package, entity string) ([]string, error)
- func FieldArgs(fields []*Field) string
- func FieldColumns(fields []*Field) string
- func FieldCriteria(fields []*Field) string
- func FieldParams(fields []*Field) string
- func Filters(pkg *ast.Package, entity string) [][]string
- func IsColumnType(name string) bool
- func Packages() (map[string]*ast.Package, error)
- func RefFilters(pkg *ast.Package, entity string, ref string) [][]string
- func UpdateSchema() error
- type Field
- type Mapping
- func (m *Mapping) ColumnFields(exclude ...string) []*Field
- func (m *Mapping) ContainsFields(fields []*Field) bool
- func (m *Mapping) FieldByName(name string) *Field
- func (m *Mapping) FieldColumnName(name string) string
- func (m *Mapping) FilterFieldByName(name string) (*Field, error)
- func (m *Mapping) NaturalKey() []*Field
- func (m *Mapping) RefFields() []*Field
- func (m *Mapping) ScalarFields() []*Field
- type Method
- type Stmt
- type Type
Constants ¶
const ( TypeColumn = iota TypeSlice TypeMap )
Possible type code.
Variables ¶
var Imports = []string{
"database/sql",
"fmt",
"github.com/lxc/lxd/lxd/db/cluster",
"github.com/lxc/lxd/lxd/db/query",
"github.com/lxc/lxd/shared/api",
"github.com/pkg/errors",
}
Imports is a list of the package imports every generated source file has.
Functions ¶
func FieldArgs ¶
FieldArgs converts the given fields to function arguments, rendering their name and type.
func FieldColumns ¶
FieldColumns converts thegiven fields to list of column names separated by a comma.
func FieldCriteria ¶
FieldCriteria converts the given fields to AND-separated WHERE criteria.
func FieldParams ¶
FieldParams converts the given fields to function parameters, rendering their name.
func Filters ¶
Filters parses all filtering statement defined for the given entity. It returns all supported combinations of filters, sorted by number of criteria.
func IsColumnType ¶
IsColumnType returns true if the given type name is one mapping directly to a database column.
func Packages ¶
Packages returns the the AST packages in which to search for structs.
By default it includes the lxd/db and shared/api packages.
func RefFilters ¶
RefFilters parses all filtering statement defined for the given entity reference.
func UpdateSchema ¶
func UpdateSchema() error
UpdateSchema updates the schema.go file of the cluster and node databases.
Types ¶
type Field ¶
type Field struct { Name string Type Type Primary bool // Whether this field is part of the natural primary key. Config url.Values }
Field holds all information about a field in a Go struct that is relevant for database code generation.
func (*Field) Column ¶
Column returns the name of the database column the field maps to. The type code of the field must be TypeColumn.
func (*Field) IsIndirect ¶
IsIndirect returns true if the field is a scalar column value from a joined table that in turn requires another join.
func (*Field) IsScalar ¶
IsScalar returns true if the field is a scalar column value from a joined table.
type Mapping ¶
type Mapping struct { Package string // Package of the Go struct Name string // Name of the Go struct. Fields []*Field // Metadata about the Go struct. }
Mapping holds information for mapping database tables to a Go structure.
func (*Mapping) ColumnFields ¶
ColumnFields returns the fields that map directly to a database column, either on this table or on a joined one.
func (*Mapping) ContainsFields ¶
ContainsFields checks that the mapping contains fields with the same type and name of given ones.
func (*Mapping) FieldByName ¶
FieldByName returns the field with the given name, if any.
func (*Mapping) FieldColumnName ¶
FieldColumnName returns the column name of the field with the given name, prefixed with the entity's table name.
func (*Mapping) FilterFieldByName ¶
FilterFieldByName returns the field with the given name if that field can be used as query filter, an error otherwise.
func (*Mapping) NaturalKey ¶
NaturalKey returns the struct fields that can be used as natural key for uniquely identifying a row in the underlying table (==.
By convention the natural key field is the one called "Name", unless specified otherwise with the `db:natural_key` tags.
func (*Mapping) RefFields ¶
RefFields returns the fields that are one-to-many references to other tables.
func (*Mapping) ScalarFields ¶
ScalarFields returns the fields that map directly to a single database column on another table that can be joined to this one.
type Method ¶
type Method struct {
// contains filtered or unexported fields
}
Method generates a code snippet for a particular database query method.