types

package
v0.0.0-...-56451d9 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 8 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.

Types

type ContextKey

type ContextKey string

ContextKey is a context key.

const (
	DriverKey ContextKey = "driver"
	DbKey     ContextKey = "db"
	SchemaKey ContextKey = "schema"
)

Context key values.

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"`
}

Field is a column, index, enum value, or stored procedure parameter.

type Flag

type Flag struct {
	ContextKey  ContextKey
	Type        string
	Desc        string
	PlaceHolder string
	Default     string
	Short       rune
	Enums       []string
}

Flag is a option flag.

type FlagSet

type FlagSet struct {
	Type string
	Name string
	Flag Flag
}

FlagSet is a set of flags for a driver.

func (FlagSet) Add

func (flag FlagSet) Add(cmd *kingpin.CmdClause, flags map[ContextKey]interface{})

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 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 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 XO

type XO struct {
	Queries []Query  `json:"queries,omitempty"`
	Schemas []Schema `json:"schemas,omitempty"`
}

XO wraps query and schema information.

func (*XO) Emit

func (x *XO) Emit(v ...interface{})

Emit emits values.

Jump to

Keyboard shortcuts

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