Documentation ¶
Overview ¶
Package types contains xo internal types.
Index ¶
- func DriverDbSchema(ctx context.Context) (string, *sql.DB, string)
- func Out(ctx context.Context) string
- func Single(ctx context.Context) string
- type ContextKey
- type Enum
- type Field
- type Flag
- type FlagSet
- type ForeignKey
- type Index
- type Proc
- type Query
- type Schema
- type Set
- type Table
- type Template
- type TemplateType
- type Type
- type Value
- func (v *Value) AsBool() bool
- func (v *Value) AsGlob() []glob.Glob
- func (v *Value) AsInt() int
- func (v *Value) AsString() string
- func (v *Value) AsStringSlice() []string
- func (v *Value) Desc() string
- func (v *Value) Interface() interface{}
- func (v *Value) Set(s string) error
- func (v *Value) String() string
- func (v *Value) Type() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DriverDbSchema ¶
DriverDbSchema returns the driver, database connection, and schema name from the context.
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is a context key.
const ( DriverKey ContextKey = "driver" DbKey ContextKey = "db" SchemaKey ContextKey = "schema" OutKey ContextKey = "out" SingleKey ContextKey = "single" )
Context keys.
type Field ¶
type Field struct { Name string `json:"name,omitempty"` Type Type `json:"datatype,omitempty"` Default string `json:"default,omitempty"` IsPrimary bool `json:"is_primary,omitempty"` IsSequence bool `json:"is_sequence,omitempty"` ConstValue *int `json:"const_value,omitempty"` Interpolate bool `json:"interpolate,omitempty"` Join bool `json:"join,omitempty"` }
Field is a column, index, enum value, or stored procedure parameter.
type Flag ¶
type Flag struct { ContextKey ContextKey Type string Desc string Default string Short string Enums []string Aliases []string Hidden bool }
Flag is a option flag.
type ForeignKey ¶
type ForeignKey struct { Name string `json:"name,omitempty"` // constraint name Fields []Field `json:"column,omitempty"` // column that has the key on it RefTable string `json:"ref_table,omitempty"` // table the foreign key refers to RefFields []Field `json:"ref_column,omitempty"` // column in ref table the index refers to Func string `json:"-"` // foreign key func name (based on fkey mode) RefFunc string `json:"-"` // func name from ref index }
ForeignKey is a foreign key.
type Index ¶
type Index struct { Name string `json:"name,omitempty"` Fields []Field `json:"fields,omitempty"` IsUnique bool `json:"is_unique,omitempty"` IsPrimary bool `json:"is_primary,omitempty"` Func string `json:"-"` }
Index is a index.
type Proc ¶
type Proc struct { ID string `json:"-"` Type string `json:"type,omitempty"` // 'procedure' or 'function' Name string `json:"name,omitempty"` Params []Field `json:"params,omitempty"` Returns []Field `json:"return,omitempty"` Void bool `json:"void,omitempty"` Definition string `json:"definition,omitempty"` }
Proc is a stored procedure.
func (Proc) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface.
type Query ¶
type Query struct { Driver string `json:"driver,omitempty"` Name string `json:"name,omitempty"` Comment string `json:"comment,omitempty"` Exec bool `json:"exec,omitempty"` Flat bool `json:"flat,omitempty"` One bool `json:"one,omitempty"` Interpolate bool `json:"interpolate,omitempty"` Type string `json:"type,omitempty"` TypeComment string `json:"type_comment,omitempty"` Fields []Field `json:"fields,omitempty"` ManualFields bool `json:"manual_fields,omitempty"` // fields generated or provided by user Params []Field `json:"params,omitempty"` Query []string `json:"query,omitempty"` Comments []string `json:"comments,omitempty"` }
Query is a query.
func (Query) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface.
type Schema ¶
type Schema struct { Driver string `json:"type,omitempty"` Name string `json:"name,omitempty"` Enums []Enum `json:"enums,omitempty"` Procs []Proc `json:"procs,omitempty"` Tables []Table `json:"tables,omitempty"` Views []Table `json:"views,omitempty"` }
Schema is a SQL schema.
func (Schema) EnumByName ¶
EnumByName returns a enum by its name.
type Set ¶
type Set struct { Queries []Query `json:"queries,omitempty"` Schemas []Schema `json:"schemas,omitempty"` }
Set is a set of queries and schemas.
type Table ¶
type Table struct { Type string `json:"type,omitempty"` // 'table' or 'view' Name string `json:"name,omitempty"` Columns []Field `json:"columns,omitempty"` PrimaryKeys []Field `json:"primary_keys,omitempty"` Indexes []Index `json:"indexes,omitempty"` ForeignKeys []ForeignKey `json:"foreign_keys,omitempty"` Manual bool `json:"manual,omitempty"` Definition string `json:"definition,omitempty"` // empty for tables }
Table is a table or view.
func (Table) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface.
type Template ¶
type Template struct { // Src is the source of the template and will be used when it is non-empty. Src string // Partial is the partial template name to use, if any. Partial string // Dest is the destination file. Dest string // SortType is the sort order type. SortType string // SortName is the name to sort by. SortName string // Data is the template data. Data interface{} }
Template holds template information.
type TemplateType ¶
type TemplateType struct { // Name is the template name. Name string // Modes are the command modes the template is available for. Modes []string // Flags are additional template flags. Flags []Flag // Order returns the order of template type processing. Order func(ctx context.Context, mode string) []string // Funcs provides template funcs for use by templates. Funcs func(ctx context.Context, mode string) (template.FuncMap, error) // NewContext provides a way for templates to inject additional, global // context values, prior to processing. NewContext func(ctx context.Context, mode string) context.Context // Pre performs pre processing of generated content, such as emitting // static files. Pre func(ctx context.Context, mode string, set *Set, outFolder fs.FS, emit func(Template)) error // Process performs the processing templates for the set. Process func(ctx context.Context, mode string, set *Set, emit func(Template)) error // Post performs post processing of generated content. Post func(ctx context.Context, mode string, files map[string][]byte, emit func(string, []byte)) error }
TemplateType is a template type.
type Type ¶
type Type struct { Type string `json:"type,omitempty"` Prec int `json:"prec,omitempty"` Scale int `json:"scale,omitempty"` Nullable bool `json:"nullable,omitempty"` IsArray bool `json:"array,omitempty"` Unsigned bool `json:"unsigned,omitempty"` Enum *Enum `json:"-"` }
Type holds information for a database type.
func ParseType ¶
ParseType parses "type[ (precision[,scale])][\[\]]" strings returning the parsed precision, scale, and if the type is an array or not.
Expected formats:
type type(precision) type(precision, scale) type(precision, scale) unsigned timestamp(n) with [local] time zone (oracle only)
The returned type is stripped of precision and scale.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value wraps a flag value.
func (*Value) AsStringSlice ¶
AsStringSlice returns the value as a string slice.