schema

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License: MIT Imports: 5 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 {
	Name           gds.String           `db:"name"`
	TableName      gds.String           `db:"table_name"`
	Type           Type                 `db:"-"`
	TypeRaw        gds.String           `db:"type_raw"`
	Nullable       bool                 `db:"nullable"`
	PrimaryKey     *PrimaryKey          `db:"-"`
	UniqueKey      *UniqueKey           `db:"-"`
	ForeignKey     *ForeignKey          `db:"-"`
	Comment        gds.String           `db:"comment"`
	DefaultRaw     sql.NullString       `db:"default_value"`
	Default        *ColumnDefault       `db:"-"`
	UsingSequences map[string]*Sequence `db:"-"`
	Enum           *Enum                `db:"-"`

	IsAutoincrement bool `db:"-"`
}

func (*Column) HasForeignKey

func (c *Column) HasForeignKey() bool

func (*Column) IsPrimaryKey

func (c *Column) IsPrimaryKey() bool

func (*Column) IsUniqueKey

func (c *Column) IsUniqueKey() bool

func (*Column) IsUniqueOrPrimaryKey added in v0.1.1

func (c *Column) IsUniqueOrPrimaryKey() bool

type ColumnDefault added in v0.3.0

type ColumnDefault struct {
	Type  ColumnDefaultType
	Value interface{}
}

type ColumnDefaultType added in v0.3.0

type ColumnDefaultType int
const (
	ColumnDefaultTypeUnknown ColumnDefaultType = iota
	ColumnDefaultTypeFunc                      // @todo need refactor to expression
	ColumnDefaultTypeValue
	ColumnDefaultTypeAutoincrement
)

type Enum added in v0.3.0

type Enum struct {
	Name   *gds.String
	Values []string
	Used   int
}

func (*Enum) UsedOnce added in v0.4.0

func (e *Enum) UsedOnce() bool

type ForeignKey

type ForeignKey struct {
	Name          gds.String
	Table         gds.String
	ColumnsNames  *gds.Strings
	ForeignTable  gds.String
	ForeignColumn gds.String

	IsDeferrable        bool
	IsInitiallyDeferred bool
}

type PrimaryKey

type PrimaryKey struct {
	Name         gds.String
	ColumnsNames *gds.Strings
}

func CreatePrimaryKeyForColumn added in v0.4.0

func CreatePrimaryKeyForColumn(col *Column) *PrimaryKey

type Schema

type Schema struct {
	Tables    *TableMap
	Sequences map[string]*Sequence
	Enums     map[string]*Enum

	Driver config.DatabaseDriver
}

func NewSchema added in v0.4.0

func NewSchema(driver config.DatabaseDriver) *Schema

func (*Schema) Clone added in v0.3.0

func (s *Schema) Clone() *Schema

func (*Schema) OnlyTables added in v0.4.0

func (s *Schema) OnlyTables(tableNames []string) *Schema

func (*Schema) SortByRelations

func (s *Schema) SortByRelations()

func (*Schema) TablesNames

func (s *Schema) TablesNames() []string

func (*Schema) WithoutTable added in v0.4.0

func (s *Schema) WithoutTable(callback func(table *Table) bool) *Schema

type Sequence added in v0.3.0

type Sequence struct {
	Name        string `db:"name"`
	DataType    Type   `db:"-"`
	DataTypeRaw string `db:"data_type_raw"`
	Used        int    `db:"-"`
}

func CreateSequenceForColumn added in v0.4.0

func CreateSequenceForColumn(col *Column) *Sequence

func (*Sequence) Inc added in v0.4.0

func (s *Sequence) Inc()

func (*Sequence) UsedOnce added in v0.4.0

func (s *Sequence) UsedOnce() bool

type Table

type Table struct {
	Name    gds.String `db:"Name"`
	Columns []*Column  `db:"-"`

	PrimaryKey  *PrimaryKey            `db:"-"`
	ForeignKeys map[string]*ForeignKey `db:"-"`
	UniqueKeys  map[string]*UniqueKey  `db:"-"`

	UsingSequences map[string]*Sequence `db:"-"`
	UsingEnums     map[string]*Enum     `db:"-"`

	Comment string
	// contains filtered or unexported fields
}

func NewTable added in v0.5.0

func NewTable(name gds.String) *Table

func (*Table) AddColumn added in v0.5.0

func (t *Table) AddColumn(col *Column)

func (*Table) AddEnum added in v0.5.0

func (t *Table) AddEnum(enum *Enum)

func (*Table) ColumnsNames

func (t *Table) ColumnsNames() []string

func (*Table) GetColumn added in v0.4.0

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

func (*Table) GetFirstUniqueKey

func (t *Table) GetFirstUniqueKey() *UniqueKey

func (*Table) GetPKColumns added in v0.3.0

func (t *Table) GetPKColumns() []*Column

func (*Table) HasForeignKeyTo

func (t *Table) HasForeignKeyTo(tableName string) bool

func (*Table) HasSingleUniqueKey

func (t *Table) HasSingleUniqueKey() bool

func (*Table) HasUniqueKeys

func (t *Table) HasUniqueKeys() bool

type TableMap

type TableMap struct {
	// contains filtered or unexported fields
}

func NewTableMap

func NewTableMap(table ...*Table) *TableMap

func (*TableMap) Add

func (m *TableMap) Add(table *Table)

func (*TableMap) Clone added in v0.3.0

func (m *TableMap) Clone() *TableMap

func (*TableMap) Each

func (m *TableMap) Each(callback func(table *Table))

func (*TableMap) EachWithErr

func (m *TableMap) EachWithErr(callback func(table *Table) error) error

func (*TableMap) Get

func (m *TableMap) Get(name gds.String) (*Table, bool)

func (*TableMap) Has

func (m *TableMap) Has(name gds.String) bool

func (*TableMap) Len

func (m *TableMap) Len() int

func (*TableMap) List

func (m *TableMap) List() []*Table

type Type added in v0.4.0

type Type struct {
	Name string

	Length string

	IsNumeric    bool
	IsInteger    bool
	IsFloat      bool
	IsUUID       bool
	IsStringable bool
	IsDatetime   bool
	IsDate       bool
	IsBoolean    bool
	IsBinary     bool
	IsJSON       bool
}

func (*Type) Clone added in v0.4.0

func (t *Type) Clone() Type

func (*Type) MarkAsUUID added in v0.4.0

func (t *Type) MarkAsUUID() Type

func (*Type) String added in v0.4.0

func (t *Type) String() string

func (*Type) WithLength added in v0.4.0

func (t *Type) WithLength(length string) Type

type UniqueKey

type UniqueKey struct {
	Name         gds.String
	ColumnsNames *gds.Strings
}

func CreateUniqueKeyForColumn added in v0.5.0

func CreateUniqueKeyForColumn(col *Column) *UniqueKey

Jump to

Keyboard shortcuts

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