types

package
v0.0.0-...-de94dfd Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package types contains xo internal types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DriverDbSchema

func DriverDbSchema(ctx context.Context) (string, *sql.DB, string)

DriverDbSchema returns the driver, database connection, and schema name from the context.

func Out

func Out(ctx context.Context) string

Out returns out option from the context.

func Single

func Single(ctx context.Context) string

Single returns the file to write to in single mode.

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"
	ArrayModeKey ContextKey = "array-mode"
)

Context keys.

type Enum

type Enum struct {
	Name   string  `json:"name,omitempty"`
	Values []Field `json:"values,omitempty"`
}

Enum is a enum type.

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"`
	Comment     string `json:"comment,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 FlagSet

type FlagSet struct {
	Type string
	Name string
	Flag Flag
}

FlagSet is a set of option flags.

func (FlagSet) Add

func (flag FlagSet) Add(cmd *cobra.Command, values map[ContextKey]*Value) error

Add adds the flag to the cmd.

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

func (p Proc) MarshalYAML() (interface{}, error)

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

func (q Query) MarshalYAML() (interface{}, error)

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

func (s Schema) EnumByName(name string) *Enum

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

func (t Table) MarshalYAML() (interface{}, error)

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

func ParseType(typ, driver string) (Type, error)

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 NewValue

func NewValue(typ, def, desc string, enums ...string) *Value

NewValue creates a new flag value.

func (*Value) AsBool

func (v *Value) AsBool() bool

AsBool returns the value as a bool.

func (*Value) AsGlob

func (v *Value) AsGlob() []glob.Glob

AsGlob returns the value as a glob slice.

func (*Value) AsInt

func (v *Value) AsInt() int

AsInt returns the value as a int.

func (*Value) AsString

func (v *Value) AsString() string

AsString returns the value as a string.

func (*Value) AsStringSlice

func (v *Value) AsStringSlice() []string

AsStringSlice returns the value as a string slice.

func (*Value) Desc

func (v *Value) Desc() string

Desc returns the usage description for the flag value.

func (*Value) Interface

func (v *Value) Interface() interface{}

Interface returns the value.

func (*Value) Set

func (v *Value) Set(s string) error

Set satisfies the pflag.Value interface.

func (*Value) String

func (v *Value) String() string

String satisfies the pflag.Value interface.

func (*Value) Type

func (v *Value) Type() string

Type satisfies the pflag.Value interface.

Jump to

Keyboard shortcuts

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