tbls: github.com/k1LoW/tbls/schema Index | Files

package schema

import "github.com/k1LoW/tbls/schema"

Index

Package Files

json.go schema.go yaml.go

Constants

const (
    TypeFK = "FOREIGN KEY"
)

type Column Uses

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 Uses

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

MarshalJSON return custom JSON byte

func (Column) MarshalYAML Uses

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

MarshalYAML return custom YAML byte

func (*Column) UnmarshalJSON Uses

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

UnmarshalJSON unmarshal JSON to schema.Column

func (*Column) UnmarshalYAML Uses

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

UnmarshalYAML unmarshal YAML to schema.Column

type Constraint Uses

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

Constraint is the struct for database constraint

type Driver Uses

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 Uses

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

MarshalJSON return custom JSON byte

type DriverMeta Uses

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 Uses

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

Index is the struct for database index

type Label Uses

type Label struct {
    Name    string
    Virtual bool
}

type Labels Uses

type Labels []*Label

func (Labels) Merge Uses

func (labels Labels) Merge(name string) Labels

type Relation Uses

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 Uses

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

MarshalJSON return custom JSON byte

func (Relation) MarshalYAML Uses

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

MarshalYAML return custom YAML byte

func (*Relation) UnmarshalJSON Uses

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

UnmarshalJSON unmarshal JSON to schema.Column

func (*Relation) UnmarshalYAML Uses

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

UnmarshalYAML unmarshal YAML to schema.Column

type Schema Uses

type Schema struct {
    Name      string      `json:"name"`
    Desc      string      `json:"desc"`
    Tables    []*Table    `json:"tables"`
    Relations []*Relation `json:"relations"`
    Driver    *Driver     `json:"driver"`
    Labels    Labels      `json:"labels,omitempty"`
}

Schema is the struct for database schema

func (*Schema) FindTableByName Uses

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

FindTableByName find table by table name

func (Schema) MarshalJSON Uses

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

MarshalJSON return custom JSON byte

func (*Schema) NormalizeTableName Uses

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

func (*Schema) NormalizeTableNames Uses

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

func (*Schema) Repair Uses

func (s *Schema) Repair() error

Repair column relations

func (*Schema) Sort Uses

func (s *Schema) Sort() error

Sort schema tables, columns, relations, and constrains

type Table Uses

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"`
    Labels      Labels        `json:"labels,omitempty"`
}

Table is the struct for database table

func (*Table) CollectTablesAndRelations Uses

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

func (*Table) FindColumnByName Uses

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

FindColumnByName find column by column name

func (*Table) FindConstrainsByColumnName Uses

func (t *Table) FindConstrainsByColumnName(name string) []*Constraint

func (*Table) FindConstraintByName Uses

func (t *Table) FindConstraintByName(name string) (*Constraint, error)

FindConstraintByName find constraint by constraint name

func (*Table) FindIndexByName Uses

func (t *Table) FindIndexByName(name string) (*Index, error)

FindIndexByName find index by index name

func (*Table) FindTriggerByName Uses

func (t *Table) FindTriggerByName(name string) (*Trigger, error)

FindTriggerByName find trigger by trigger name

func (Table) MarshalJSON Uses

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

MarshalJSON return custom JSON byte

type Trigger Uses

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

Trigger is the struct for database trigger

Package schema imports 8 packages (graph) and is imported by 21 packages. Updated 2020-05-12. Refresh now. Tools for package owners.