schema

package
v1.77.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 10 Imported by: 10

Documentation

Index

Constants

View Source
const (
	ColumnExtraDef    = "ExtraDef"
	ColumnOccurrences = "Occurrences"
	ColumnPercents    = "Percents"
	ColumnChildren    = "Children"
	ColumnParents     = "Parents"
	ColumnComment     = "Comment"
	ColumnLabels      = "Labels"
)
View Source
const (
	TypeFK = "FOREIGN KEY"
)

Variables

Functions

This section is empty.

Types

type Cardinality added in v1.59.0

type Cardinality string
const (
	ZeroOrOne          Cardinality = "Zero or one"
	ExactlyOne         Cardinality = "Exactly one"
	ZeroOrMore         Cardinality = "Zero or more"
	OneOrMore          Cardinality = "One or more"
	UnknownCardinality Cardinality = ""
)

func ToCardinality added in v1.59.0

func ToCardinality(in string) (Cardinality, error)

func (Cardinality) String added in v1.59.0

func (c Cardinality) String() string

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"`
	ExtraDef        string          `json:"extra_def,omitempty" yaml:"extraDef,omitempty"`
	Occurrences     sql.NullInt32   `json:"occurrences,omitempty" yaml:"occurrences,omitempty"`
	Percents        sql.NullFloat64 `json:"percents,omitempty" yaml:"percents,omitempty"`
	Labels          Labels          `json:"labels,omitempty"`
	ParentRelations []*Relation     `json:"-"`
	ChildRelations  []*Relation     `json:"-"`
	PK              bool            `json:"-"`
	FK              bool            `json:"-"`
	HideForER       bool            `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"`
	ReferencedTable   *string  `json:"referenced_table" yaml:"referencedTable"`
	Columns           []string `json:"columns"`
	ReferencedColumns []string `json:"referenced_columns" yaml:"referencedColumns"`
	Comment           string   `json:"comment"`
}

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 FilterOption added in v1.66.0

type FilterOption struct {
	Include       []string
	Exclude       []string
	IncludeLabels []string
	Distance      int
}

type Function added in v1.56.0

type Function struct {
	Name       string `json:"name"`
	ReturnType string `json:"return_type" yaml:"returnType"`
	Arguments  string `json:"arguments"`
	Type       string `json:"type"`
}

Function is the struct for tbls stored procedure/function information

func (Function) MarshalJSON added in v1.56.0

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

MarshalJSON return custom JSON byte

type Index

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 added in v1.31.0

type Label struct {
	Name    string
	Virtual bool
}

type Labels added in v1.31.0

type Labels []*Label

func (Labels) Contains added in v1.66.0

func (labels Labels) Contains(name string) bool

func (Labels) Merge added in v1.31.0

func (labels Labels) Merge(name string) Labels

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"`
	Cardinality       Cardinality `json:"cardinality"`
	ParentCardinality Cardinality `json:"parent_cardinality" yaml:"parentCardinality"`
	Def               string      `json:"def"`
	Virtual           bool        `json:"virtual"`
	HideForER         bool        `json:"-"`
}

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.Relation

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"`
	Desc       string      `json:"desc"`
	Tables     []*Table    `json:"tables"`
	Relations  []*Relation `json:"relations"`
	Functions  []*Function `json:"functions"`
	Driver     *Driver     `json:"driver"`
	Labels     Labels      `json:"labels,omitempty"`
	Viewpoints Viewpoints  `json:"viewpoints,omitempty"`
}

Schema is the struct for database schema

func (*Schema) Clone added in v1.66.0

func (s *Schema) Clone() (c *Schema, err error)

func (*Schema) CloneWithoutViewpoints added in v1.67.0

func (s *Schema) CloneWithoutViewpoints() (c *Schema, err error)

func (*Schema) Filter added in v1.66.0

func (s *Schema) Filter(opt *FilterOption) error

func (*Schema) FindRelation added in v1.45.1

func (s *Schema) FindRelation(cs, pcs []*Column) (*Relation, error)

FindRelation find relation by columns and parent columns

func (*Schema) FindTableByName

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

FindTableByName find table by table name

func (*Schema) HasTableWithLabels added in v1.54.0

func (s *Schema) HasTableWithLabels() bool

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) SepareteTablesThatAreIncludedOrNot added in v1.67.0

func (s *Schema) SepareteTablesThatAreIncludedOrNot(opt *FilterOption) ([]*Table, []*Table, error)

func (*Schema) Sort added in v0.2.0

func (s *Schema) Sort() error

Sort schema tables, columns, relations, constrains, and viewpoints

type Table

type Table struct {
	Name             string            `json:"name"`
	Type             string            `json:"type"`
	Comment          string            `json:"comment"`
	Columns          []*Column         `json:"columns"`
	Viewpoints       []*TableViewpoint `json:"viewpoints"`
	Indexes          []*Index          `json:"indexes"`
	Constraints      []*Constraint     `json:"constraints"`
	Triggers         []*Trigger        `json:"triggers"`
	Def              string            `json:"def"`
	Labels           Labels            `json:"labels,omitempty"`
	ReferencedTables []*Table          `json:"referenced_tables,omitempty" yaml:"referencedTables,omitempty"`
	External         bool              `json:"-"` // Table external to the schema
}

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) FindConstrainsByColumnName added in v1.33.0

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

FindConstrainsByColumnName find constraint by column name

func (*Table) FindConstraintByName added in v1.37.0

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

FindConstraintByName find constraint by constraint name

func (*Table) FindIndexByName added in v1.37.0

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

FindIndexByName find index by index name

func (*Table) FindTriggerByName added in v1.37.0

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

FindTriggerByName find trigger by trigger name

func (Table) MarshalJSON added in v1.25.1

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

MarshalJSON return custom JSON byte

func (Table) MarshalYAML added in v1.51.0

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

MarshalYAML return custom JSON byte

func (*Table) ShowColumn added in v1.56.0

func (t *Table) ShowColumn(name string, hideColumns []string) bool

func (*Table) UnmarshalJSON added in v1.51.0

func (t *Table) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal JSON to schema.Table

func (*Table) UnmarshalYAML added in v1.55.0

func (t *Table) UnmarshalYAML(data []byte) error

UnmarshalYAML unmarshal YAML to schema.Table

type TableViewpoint added in v1.71.0

type TableViewpoint struct {
	Index int    `json:"index"`
	Name  string `json:"name"`
	Desc  string `json:"desc"`
}

type Trigger added in v1.0.0

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

Trigger is the struct for database trigger

type Viewpoint added in v1.66.0

type Viewpoint struct {
	Name     string            `json:"name,omitempty"`
	Desc     string            `json:"desc,omitempty"`
	Labels   []string          `json:"labels,omitempty"`
	Tables   []string          `json:"tables,omitempty"`
	Distance int               `json:"distance,omitempty"`
	Groups   []*ViewpointGroup `json:"groups,omitempty"`

	Schema *Schema `json:"-"`
}

Viewpoint is the struct for viewpoint information

type ViewpointGroup added in v1.67.0

type ViewpointGroup struct {
	Name   string   `json:"name,omitempty"`
	Desc   string   `json:"desc,omitempty"`
	Labels []string `json:"labels,omitempty"`
	Tables []string `json:"tables,omitempty"`
	Color  string   `json:"color,omitempty"`
}

type Viewpoints added in v1.66.0

type Viewpoints []*Viewpoint

func (Viewpoints) Merge added in v1.66.0

func (vs Viewpoints) Merge(in *Viewpoint) Viewpoints

Jump to

Keyboard shortcuts

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