database

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	validation.Validatable `json:"-"`
	Kind                   data.Kind `json:"kind"                yaml:"Kind"`
	Name                   string    `json:"name"                yaml:"Name"`
	Description            string    `json:"description"         yaml:"Description"`
	Deprecated             string    `json:"deprecated"          yaml:"Deprecated"`
	NativeKind             string    `json:"native_kind"         yaml:"NativeKind"`
	Length                 int       `json:"length"              yaml:"Length"`
	NumericPrecision       int       `json:"numeric_precision"   yaml:"NumericPrecision"`
	NumericScale           int       `json:"numeric_scale"       yaml:"NumericScale"`
	DateTimePrecision      int       `json:"date_time_precision" yaml:"DateTimePrecision"`
	Codec                  string    `json:"codec"               yaml:"Codec"`
	Charset                string    `json:"charset"             yaml:"Charset"`
	Default                string    `json:"default"             yaml:"Default"`
	Validation             string    `json:"validation"          yaml:"Validation"`
	Replacement            string    `json:"replacement"         yaml:"Replacement"`
	Sensitive              bool      `json:"sensitive"           yaml:"Sensitive"`
	AutoIncrement          bool      `json:"auto_increment"      yaml:"AutoIncrement"`
	Primary                bool      `json:"primary"             yaml:"Primary"`
	Index                  bool      `json:"index"               yaml:"Index"`
	Unique                 bool      `json:"unique"              yaml:"Unique"`
	Nullable               bool      `json:"nullable"            yaml:"Nullable"`
	Creatable              bool      `json:"creatable"           yaml:"Creatable"`
	Updatable              bool      `json:"updatable"           yaml:"Updatable"`
	Readable               bool      `json:"readable"            yaml:"Readable"`
}

Column defines a single Table column structure.

func NewColumn

func NewColumn(kind data.Kind, name, nativeType string) *Column

func (*Column) Validate

func (c *Column) Validate() error

Validate makes `Column` validatable by implementing validation.Validatable interface.

type IReplacing

type IReplacing interface {
	Replace(string) string
}

IReplacing replacing interface like strings.Replacer

type NamingStrategy

type NamingStrategy struct {
	SchemaNameLength int        `json:"schema_name_length" yaml:"SchemaNameLength"`
	TableNameLength  int        `json:"table_name_length"  yaml:"TableNameLength"`
	ColumnNameLength int        `json:"column_name_length" yaml:"ColumnNameLength"`
	TablePrefix      string     `json:"table_prefix"       yaml:"TablePrefix"`
	ColumnPrefix     string     `json:"column_prefix"      yaml:"ColumnPrefix"`
	SingularTable    bool       `json:"singular_table"     yaml:"SingularTable"`
	NoLowerCase      bool       `json:"no_lower_case"      yaml:"NoLowerCase"`
	NameReplacer     IReplacing `json:"-"`
}

NamingStrategy naming strategy

func (NamingStrategy) CheckerName

func (ns NamingStrategy) CheckerName(table, column string) string

CheckerName generate checker name

func (NamingStrategy) ColumnName

func (ns NamingStrategy) ColumnName(table, column string) string

ColumnName convert string to column name

func (NamingStrategy) IndexName

func (ns NamingStrategy) IndexName(table, column string) string

IndexName generate index name

func (NamingStrategy) JoinTableName

func (ns NamingStrategy) JoinTableName(str string) string

JoinTableName convert string to join table name

func (NamingStrategy) SchemaName

func (ns NamingStrategy) SchemaName(table string) string

SchemaName generate schema name from table name, don't guarantee it is the reverse value of TableName

func (NamingStrategy) TableName

func (ns NamingStrategy) TableName(str string) string

TableName convert string to table name

func (NamingStrategy) UniqueIndexName

func (ns NamingStrategy) UniqueIndexName(table, column string) string

UniqueIndexName generate unique index name

type Schema

type Schema struct {
	validation.Validatable `json:"-"`
	Name                   string         `json:"name"            yaml:"Name"`
	Description            string         `json:"description"     yaml:"Description"`
	Deprecated             string         `json:"deprecated"      yaml:"Deprecated"`
	Documentation          string         `json:"documentation"   yaml:"Documentation"`
	Encoding               string         `json:"encoding"        yaml:"Encoding"`
	Tables                 []*Table       `json:"tables"          yaml:"Tables"`
	NamingStrategy         NamingStrategy `json:"naming_strategy" yaml:"NamingStrategy"`
	// contains filtered or unexported fields
}

Schema defines a single schema structure.

func NewSchema

func NewSchema(name, description string, tables ...*Table) *Schema

func (*Schema) CreateTable

func (s *Schema) CreateTable(table *Table)

CreateTable add a single table to the schema.

func (*Schema) DropTable

func (s *Schema) DropTable(name string)

DropTable delete a single table by its name.

func (*Schema) Table

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

Table returns a single table by its name.

func (*Schema) TablePosition

func (s *Schema) TablePosition(name string) int

TablePosition returns the index of a table by its name.

func (*Schema) Validate

func (s *Schema) Validate() error

Validate makes Schema validatable by implementing validation.Validatable interface.

type Table

type Table struct {
	validation.Validatable `json:"-"`
	Name                   string    `json:"name"        yaml:"Name"`
	Description            string    `json:"description" yaml:"Description"`
	Deprecated             string    `json:"deprecated"  yaml:"Deprecated"`
	Engine                 string    `json:"engine"      yaml:"Engine"`
	Codec                  string    `json:"codec"       yaml:"Codec"`
	Charset                string    `json:"charset"     yaml:"Charset"`
	ReadOnly               bool      `json:"read_only"   yaml:"ReadOnly"`
	Columns                []*Column `json:"columns"     yaml:"Columns"`
	// contains filtered or unexported fields
}

Table defines a single Schema table structure.

func NewTable

func NewTable(name, description string, columns ...*Column) *Table

func (*Table) Column

func (t *Table) Column(name string) *Column

Column returns a single column by its name.

func (*Table) ColumnPosition

func (t *Table) ColumnPosition(name string) int

ColumnPosition returns the index of a column by its name.

func (*Table) CreateColumn

func (t *Table) CreateColumn(column *Column)

CreateColumn add a single column to the table.

func (*Table) DropColumn

func (t *Table) DropColumn(name string)

DropColumn delete a single column by its name.

func (*Table) Validate

func (t *Table) Validate() error

Validate makes Table validatable by implementing validation.Validatable interface.

Jump to

Keyboard shortcuts

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