schema

package
v1.85.4-souhl.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: MIT Imports: 10 Imported by: 0

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

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

func ToCardinality(in string) (Cardinality, error)

func (Cardinality) String

func (c Cardinality) String() string

type Column

type Column struct {
	Name     string
	Type     string
	Nullable bool
	Default  sql.NullString
	Comment  string `json:"comment,omitempty"`
	// ドキュメント用マスキング種別(lint で必須)
	MaskingType     string `json:"maskingType,omitempty" yaml:"maskingType,omitempty"`
	ExtraDef        string
	Occurrences     sql.NullInt32
	Percents        sql.NullFloat64
	Labels          Labels
	ParentRelations []*Relation
	ChildRelations  []*Relation
	PK              bool
	FK              bool
	HideForER       bool
}

Column is the struct for table column.

func (Column) MarshalJSON

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

MarshalJSON return custom JSON byte.

func (Column) MarshalYAML

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

MarshalYAML return custom YAML byte.

func (Column) ToJSONObject

func (c Column) ToJSONObject() ColumnJSON

func (*Column) UnmarshalJSON

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

UnmarshalJSON unmarshal JSON to schema.Column.

func (*Column) UnmarshalYAML

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

UnmarshalYAML unmarshal YAML to schema.Column.

type ColumnJSON

type ColumnJSON struct {
	Name     string  `json:"name"`
	Type     string  `json:"type"`
	Nullable bool    `json:"nullable"`
	Default  *string `json:"default,omitempty" jsonschema:"anyof_type=string;null"`
	ExtraDef string  `json:"extra_def,omitempty"`
	Labels   Labels  `json:"labels,omitempty"`
	Comment  string  `json:"comment,omitempty"`
}

ColumnJSON is a JSON representation of schema.Column.

type Constraint

type Constraint struct {
	Name              string   `json:"name"`
	Type              string   `json:"type"`
	Def               string   `json:"def"`
	Table             *string  `json:"table"`
	ReferencedTable   *string  `json:"referenced_table,omitempty" yaml:"referencedTable,omitempty"`
	Columns           []string `json:"columns,omitempty"`
	ReferencedColumns []string `json:"referenced_columns,omitempty" yaml:"referencedColumns,omitempty"`
	Comment           string   `json:"comment,omitempty"`
}

Constraint is the struct for database constraint.

type Driver

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

Driver is the struct for tbls driver information.

func (*Driver) ToJSONObject

func (d *Driver) ToJSONObject() *DriverJSON

type DriverJSON

type DriverJSON struct {
	Name            string          `json:"name"`
	DatabaseVersion string          `json:"database_version,omitempty" yaml:"databaseVersion,omitempty"`
	Meta            *DriverMetaJSON `json:"meta,omitempty"`
}

type DriverMeta

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

func (*DriverMeta) ToJSONObject

func (d *DriverMeta) ToJSONObject() *DriverMetaJSON

type DriverMetaJSON

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

type Enum

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

type FilterOption

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

type Function

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.

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

Index is the struct for database index.

type Label

type Label struct {
	Name    string `json:"name"`
	Virtual bool   `json:"virtual,omitempty"`
}

type Labels

type Labels []*Label

func (Labels) Contains

func (labels Labels) Contains(name string) bool

func (Labels) Merge

func (labels Labels) Merge(name string) Labels

type Relation

type Relation struct {
	Table             *Table
	Columns           []*Column
	ParentTable       *Table
	ParentColumns     []*Column
	Cardinality       Cardinality
	ParentCardinality Cardinality
	Def               string
	Virtual           bool
	HideForER         bool
}

Relation is the struct for table relation.

func (Relation) MarshalJSON

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

MarshalJSON return custom JSON byte.

func (Relation) MarshalYAML

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

MarshalYAML return custom YAML byte.

func (Relation) ToJSONObject

func (r Relation) ToJSONObject() RelationJSON

func (*Relation) UnmarshalJSON

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

UnmarshalJSON unmarshal JSON to schema.Relation.

func (*Relation) UnmarshalYAML

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

UnmarshalYAML unmarshal YAML to schema.Column.

type RelationJSON

type RelationJSON struct {
	Table             string   `json:"table"`
	Columns           []string `json:"columns"`
	Cardinality       string   `json:"cardinality,omitempty" jsonschema:"enum=zero_or_one,enum=exactly_one,enum=zero_or_more,enum=one_or_more,enum="`
	ParentTable       string   `json:"parent_table"`
	ParentColumns     []string `json:"parent_columns"`
	ParentCardinality string   `json:"parent_cardinality,omitempty" jsonschema:"enum=zero_or_one,enum=exactly_one,enum=zero_or_more,enum=one_or_more,enum="`
	Def               string   `json:"def"`
	Virtual           bool     `json:"virtual,omitempty"`
}

RelationJSON is a JSON representation of schema.Relation.

type Schema

type Schema struct {
	Name       string      `json:"name,omitempty"`
	Desc       string      `json:"desc,omitempty"`
	Tables     []*Table    `json:"tables"`
	Relations  []*Relation `json:"relations,omitempty"`
	Functions  []*Function `json:"functions,omitempty"`
	Enums      []*Enum     `json:"enums,omitempty"`
	Driver     *Driver     `json:"driver,omitempty"`
	Labels     Labels      `json:"labels,omitempty"`
	Viewpoints Viewpoints  `json:"viewpoints,omitempty"`
}

Schema is the struct for database schema.

func (*Schema) Clone

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

func (*Schema) CloneWithoutViewpoints

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

func (*Schema) Filter

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

func (*Schema) FindRelation

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

FindRelation find relation by columns and parent columns.

func (*Schema) FindTableByName

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

FindTableByName find table by table name.

func (*Schema) HasTableWithLabels

func (s *Schema) HasTableWithLabels() bool

func (Schema) MarshalJSON

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

MarshalJSON return custom JSON byte.

func (*Schema) MatchTablesByName

func (s *Schema) MatchTablesByName(name string) (_ []*Table, err error)

MatchTablesByName find table by table name.

func (*Schema) NormalizeTableName

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

func (*Schema) NormalizeTableNames

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

func (*Schema) Repair

func (s *Schema) Repair() (err error)

Repair column relations.

func (*Schema) SeparateTablesThatAreIncludedOrNot

func (s *Schema) SeparateTablesThatAreIncludedOrNot(opt *FilterOption) (_ []*Table, _ []*Table, err error)

func (*Schema) Sort

func (s *Schema) Sort() error

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

func (Schema) ToJSONObject

func (s Schema) ToJSONObject() SchemaJSON

ToJSONObjct convert schema.Schema to JSON object.

type SchemaJSON

type SchemaJSON struct {
	Name       string          `json:"name,omitempty"`
	Desc       string          `json:"desc,omitempty"`
	Tables     []*TableJSON    `json:"tables"`
	Relations  []*RelationJSON `json:"relations,omitempty"`
	Functions  []*Function     `json:"functions,omitempty"`
	Enums      []*Enum         `json:"enums,omitempty"`
	Driver     *DriverJSON     `json:"driver,omitempty"`
	Labels     Labels          `json:"labels,omitempty"`
	Viewpoints Viewpoints      `json:"viewpoints,omitempty"`
}

SchemaJSON is a JSON representation of schema.Schema.

type Table

type Table struct {
	Name             string
	Type             string
	Comment          string
	Columns          []*Column
	Viewpoints       []*TableViewpoint
	Indexes          []*Index
	Constraints      []*Constraint
	Triggers         []*Trigger
	Def              string
	Labels           Labels
	ReferencedTables []*Table
	External         bool
}

Table is the struct for database table.

func (*Table) CollectTablesAndRelations

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

func (*Table) FindColumnByName

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

FindColumnByName find column by column name.

func (*Table) FindConstrainsByColumnName

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

FindConstrainsByColumnName find constraint by column name.

func (*Table) FindConstraintByName

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

FindConstraintByName find constraint by constraint name.

func (*Table) FindIndexByName

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

FindIndexByName find index by index name.

func (*Table) FindTriggerByName

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

FindTriggerByName find trigger by trigger name.

func (Table) MarshalJSON

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

MarshalJSON return custom JSON byte.

func (Table) MarshalYAML

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

MarshalYAML return custom JSON byte.

func (*Table) ShowColumn

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

func (Table) ToJSONObject

func (t Table) ToJSONObject() TableJSON

func (*Table) UnmarshalJSON

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

UnmarshalJSON unmarshal JSON to schema.Table.

func (*Table) UnmarshalYAML

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

UnmarshalYAML unmarshal YAML to schema.Table.

type TableJSON

type TableJSON struct {
	Name             string        `json:"name"`
	Type             string        `json:"type"`
	Comment          string        `json:"comment,omitempty"`
	Columns          []*ColumnJSON `json:"columns"`
	Indexes          []*Index      `json:"indexes,omitempty"`
	Constraints      []*Constraint `json:"constraints,omitempty"`
	Triggers         []*Trigger    `json:"triggers,omitempty"`
	Def              string        `json:"def,omitempty"`
	Labels           Labels        `json:"labels,omitempty"`
	ReferencedTables []string      `json:"referenced_tables,omitempty"`
}

TableJSON is a JSON representation of schema.Table.

type TableViewpoint

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

type Trigger

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

Trigger is the struct for database trigger.

type Viewpoint

type Viewpoint struct {
	Name     string            `json:"name"`
	Desc     string            `json:"desc"`
	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

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

type Viewpoints

type Viewpoints []*Viewpoint

func (Viewpoints) Merge

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
⌂ 换网址