lxd: github.com/lxc/lxd/shared/generate/db Index | Files

package db

import "github.com/lxc/lxd/shared/generate/db"

Index

Package Files

constants.go lex.go mapping.go method.go parse.go schema.go stmt.go

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.

func Criteria Uses

func Criteria(pkg *ast.Package, entity string) ([]string, error)

func FieldArgs Uses

func FieldArgs(fields []*Field) string

FieldArgs converts the given fields to function arguments, rendering their name and type.

func FieldColumns Uses

func FieldColumns(fields []*Field) string

FieldColumns converts thegiven fields to list of column names separated by a comma.

func FieldCriteria Uses

func FieldCriteria(fields []*Field) string

FieldCriteria converts the given fields to AND-separated WHERE criteria.

func FieldParams Uses

func FieldParams(fields []*Field) string

FieldParams converts the given fields to function parameters, rendering their name.

func Filters Uses

func Filters(pkg *ast.Package, entity string) [][]string

Filters parses all filtering statement defined for the given entity. It returns all supported combinations of filters, sorted by number of criteria.

func IsColumnType Uses

func IsColumnType(name string) bool

IsColumnType returns true if the given type name is one mapping directly to a database column.

func Packages Uses

func Packages() (map[string]*ast.Package, error)

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 Uses

func RefFilters(pkg *ast.Package, entity string, ref string) [][]string

RefFilters parses all filtering statement defined for the given entity reference.

func UpdateSchema Uses

func UpdateSchema() error

UpdateSchema updates the schema.go file of the cluster and node databases.

type Field Uses

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 Uses

func (f *Field) Column() string

Column returns the name of the database column the field maps to. The type code of the field must be TypeColumn.

func (*Field) IsIndirect Uses

func (f *Field) IsIndirect() bool

IsIndirect returns true if the field is a scalar column value from a joined table that in turn requires another join.

func (*Field) IsPrimary Uses

func (f *Field) IsPrimary() bool

IsPrimary returns true if the field part of the natural key.

func (*Field) IsScalar Uses

func (f *Field) IsScalar() bool

IsScalar returns true if the field is a scalar column value from a joined table.

func (*Field) Stmt Uses

func (f *Field) Stmt() string

Stmt must be used only on a non-columnar field. It returns the name of statement that should be used to fetch this field. A statement with that name must have been generated for the entity at hand.

func (*Field) ZeroValue Uses

func (f *Field) ZeroValue() string

ZeroValue returns the literal representing the zero value for this field. The type code of the field must be TypeColumn.

type Mapping Uses

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 Parse Uses

func Parse(pkg *ast.Package, name string) (*Mapping, error)

Parse the structure declaration with the given name found in the given Go package.

func (*Mapping) ColumnFields Uses

func (m *Mapping) ColumnFields(exclude ...string) []*Field

ColumnFields returns the fields that map directly to a database column, either on this table or on a joined one.

func (*Mapping) ContainsFields Uses

func (m *Mapping) ContainsFields(fields []*Field) bool

ContainsFields checks that the mapping contains fields with the same type and name of given ones.

func (*Mapping) FieldByName Uses

func (m *Mapping) FieldByName(name string) *Field

FieldByName returns the field with the given name, if any.

func (*Mapping) FieldColumnName Uses

func (m *Mapping) FieldColumnName(name string) string

FieldColumnName returns the column name of the field with the given name, prefixed with the entity's table name.

func (*Mapping) FilterFieldByName Uses

func (m *Mapping) FilterFieldByName(name string) (*Field, error)

FilterFieldByName returns the field with the given name if that field can be used as query filter, an error otherwise.

func (*Mapping) NaturalKey Uses

func (m *Mapping) NaturalKey() []*Field

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 Uses

func (m *Mapping) RefFields() []*Field

RefFields returns the fields that are one-to-many references to other tables.

func (*Mapping) ScalarFields Uses

func (m *Mapping) ScalarFields() []*Field

ScalarFields returns the fields that map directly to a single database column on another table that can be joined to this one.

type Method Uses

type Method struct {
    // contains filtered or unexported fields
}

Method generates a code snippet for a particular database query method.

func NewMethod Uses

func NewMethod(database, pkg, entity, kind string, config map[string]string) (*Method, error)

NewMethod return a new method code snippet for executing a certain mapping.

func (*Method) Generate Uses

func (m *Method) Generate(buf *file.Buffer) error

Generate the desired method.

type Stmt Uses

type Stmt struct {
    // contains filtered or unexported fields
}

Stmt generates a particular database query statement.

func NewStmt Uses

func NewStmt(database, pkg, entity, kind string, config map[string]string) (*Stmt, error)

NewStmt return a new statement code snippet for running the given kind of query against the given database entity.

func (*Stmt) Generate Uses

func (s *Stmt) Generate(buf *file.Buffer) error

Generate plumbing and wiring code for the desired statement.

type Type Uses

type Type struct {
    Name string
    Code int
}

Type holds all information about a field in a field type that is relevant for database code generation.

Package db imports 12 packages (graph) and is imported by 5 packages. Updated 2019-10-07. Refresh now. Tools for package owners.