schema

package
v1.29.3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: MIT Imports: 8 Imported by: 17

Documentation

Index

Constants

View Source
const (
	TypeFK = "FOREIGN KEY"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name            string         `json:"name"`
	Type            string         `json:"type"`
	Nullable        bool           `json:"nullable"`
	Default         sql.NullString `json:"default"`
	Comment         string         `json:"comment"`
	ParentRelations []*Relation    `json:"-"`
	ChildRelations  []*Relation    `json:"-"`
}

Column is the struct for table column

func (Column) MarshalJSON added in v1.6.0

func (c Column) MarshalJSON() ([]byte, error)

MarshalJSON return custom JSON byte

func (Column) MarshalYAML added in v1.26.0

func (c Column) MarshalYAML() ([]byte, error)

MarshalYAML return custom YAML byte

func (*Column) UnmarshalJSON added in v1.6.0

func (c *Column) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal JSON to schema.Column

func (*Column) UnmarshalYAML added in v1.26.0

func (c *Column) UnmarshalYAML(data []byte) error

UnmarshalYAML unmarshal YAML to schema.Column

type Constraint added in v0.2.2

type Constraint struct {
	Name             string   `json:"name"`
	Type             string   `json:"type"`
	Def              string   `json:"def"`
	Table            *string  `json:"table"`
	ReferenceTable   *string  `json:"reference_table" yaml:"referenceTable"`
	Columns          []string `json:"columns"`
	ReferenceColumns []string `json:"reference_columns" yaml:"referenceColumns"`
}

Constraint is the struct for database constraint

type Driver added in v1.6.0

type Driver struct {
	Name            string      `json:"name"`
	DatabaseVersion string      `json:"database_version" yaml:"databaseVersion"`
	Meta            *DriverMeta `json:"meta"`
}

Driver is the struct for tbls driver information

func (Driver) MarshalJSON added in v1.28.0

func (d Driver) MarshalJSON() ([]byte, error)

MarshalJSON return custom JSON byte

type DriverMeta added in v1.29.0

type DriverMeta struct {
	CurrentSchema string     `json:"current_schema,omitempty" yaml:"currentSchema,omitempty"`
	SearchPaths   []string   `json:"search_paths,omitempty" yaml:"searchPaths,omitempty"`
	Dict          *dict.Dict `json:"dict,omitempty"`
}

type Index

type Index struct {
	Name    string   `json:"name"`
	Def     string   `json:"def"`
	Table   *string  `json:"table"`
	Columns []string `json:"columns"`
}

Index is the struct for database index

type Relation

type Relation struct {
	Table         *Table    `json:"table"`
	Columns       []*Column `json:"columns"`
	ParentTable   *Table    `json:"parent_table" yaml:"parentTable"`
	ParentColumns []*Column `json:"parent_columns" yaml:"parentColumns"`
	Def           string    `json:"def"`
	Virtual       bool      `json:"virtual"`
}

Relation is the struct for table relation

func (Relation) MarshalJSON added in v1.26.0

func (r Relation) MarshalJSON() ([]byte, error)

MarshalJSON return custom JSON byte

func (Relation) MarshalYAML added in v1.26.0

func (r Relation) MarshalYAML() ([]byte, error)

MarshalYAML return custom YAML byte

func (*Relation) UnmarshalJSON added in v1.26.0

func (r *Relation) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal JSON to schema.Column

func (*Relation) UnmarshalYAML added in v1.26.0

func (r *Relation) UnmarshalYAML(data []byte) error

UnmarshalYAML unmarshal YAML to schema.Column

type Schema

type Schema struct {
	Name      string      `json:"name"`
	Tables    []*Table    `json:"tables"`
	Relations []*Relation `json:"relations"`
	Driver    *Driver     `json:"driver"`
}

Schema is the struct for database schema

func (*Schema) FindTableByName

func (s *Schema) FindTableByName(name string) (*Table, error)

FindTableByName find table by table name

func (Schema) MarshalJSON added in v1.25.1

func (s Schema) MarshalJSON() ([]byte, error)

MarshalJSON return custom JSON byte

func (*Schema) NormalizeTableName added in v1.28.2

func (s *Schema) NormalizeTableName(name string) string

func (*Schema) NormalizeTableNames added in v1.28.2

func (s *Schema) NormalizeTableNames(names []string) []string

func (*Schema) Repair added in v1.6.0

func (s *Schema) Repair() error

Repair column relations

func (*Schema) Sort added in v0.2.0

func (s *Schema) Sort() error

Sort schema tables, columns, relations, and constrains

type Table

type Table struct {
	Name        string        `json:"name"`
	Type        string        `json:"type"`
	Comment     string        `json:"comment"`
	Columns     []*Column     `json:"columns"`
	Indexes     []*Index      `json:"indexes"`
	Constraints []*Constraint `json:"constraints"`
	Triggers    []*Trigger    `json:"triggers"`
	Def         string        `json:"def"`
}

Table is the struct for database table

func (*Table) CollectTablesAndRelations added in v1.27.0

func (t *Table) CollectTablesAndRelations(distance int, root bool) ([]*Table, []*Relation, error)

func (*Table) FindColumnByName

func (t *Table) FindColumnByName(name string) (*Column, error)

FindColumnByName find column by column name

func (Table) MarshalJSON added in v1.25.1

func (t Table) MarshalJSON() ([]byte, error)

MarshalJSON return custom JSON byte

type Trigger added in v1.0.0

type Trigger struct {
	Name string `json:"name"`
	Def  string `json:"def"`
}

Trigger is the struct for database trigger

Jump to

Keyboard shortcuts

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