schema

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDatabaseSchema = "public"
)

Variables

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"`
	CharacterLength int16                `db:"character_length"`
	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 Database added in v0.5.7

type Database struct {
	Driver DatabaseDriver    `yaml:"driver"`
	DSN    specw.Env[string] `yaml:"dsn"`
	Schema string            `yaml:"schema"`
}

type DatabaseDriver added in v0.5.7

type DatabaseDriver string
const (
	DatabaseDriverPostgres DatabaseDriver = "postgres"
	DatabaseDriverDBML     DatabaseDriver = "dbml"
	DatabaseDriverMySQL    DatabaseDriver = "mysql"
)

func GetReadableDatabaseDrivers added in v0.5.7

func GetReadableDatabaseDrivers() []DatabaseDriver

func GetWriteableDatabaseDrivers added in v0.5.7

func GetWriteableDatabaseDrivers() []DatabaseDriver

func (DatabaseDriver) CanMigrate added in v0.5.7

func (d DatabaseDriver) CanMigrate() bool

func (DatabaseDriver) CanRead added in v0.5.7

func (d DatabaseDriver) CanRead() bool

func (DatabaseDriver) CanWrite added in v0.5.7

func (d DatabaseDriver) CanWrite() bool

func (DatabaseDriver) Valid added in v0.5.7

func (d DatabaseDriver) Valid() bool

type Enum added in v0.3.0

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

	// List of names of tables, which using this enum.
	UsingInTables []string
}

func (*Enum) UsingInSingleTable added in v0.5.5

func (e *Enum) UsingInSingleTable() 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
}

type Schema

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

	Driver DatabaseDriver
}

func NewSchema added in v0.4.0

func NewSchema(driver 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

func (*Table) SupportsSoftDelete added in v0.5.7

func (t *Table) SupportsSoftDelete() 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
	IsInterval   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
}

Jump to

Keyboard shortcuts

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