Help us shape the future of Go! Take the 2026 Go Developer Survey

schema

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	Dialect Dialect
	Exec    Executor
}

func (*Builder) AlterTable

func (b *Builder) AlterTable(name string, fn func(*Table)) error

func (*Builder) CreateTable

func (b *Builder) CreateTable(name string, fn func(*Table)) error

func (*Builder) CreateTableIfNotExists

func (b *Builder) CreateTableIfNotExists(name string, fn func(*Table)) error

func (*Builder) DropTable

func (b *Builder) DropTable(name string) error

func (*Builder) DropTableIfExists

func (b *Builder) DropTableIfExists(name string) error

func (*Builder) HasTable

func (b *Builder) HasTable(name string) (bool, error)

type Column

type Column struct {
	Name           string
	Type           string
	IsNullable     bool
	IsUnique       bool
	IsPrimary      bool
	IsAuto         bool
	DefaultValue   any
	ReferenceTable string
	ReferenceCol   string
}

func (*Column) AutoIncrement

func (c *Column) AutoIncrement() *Column

func (*Column) Default

func (c *Column) Default(val any) *Column

func (*Column) NotNull

func (c *Column) NotNull() *Column

func (*Column) Nullable

func (c *Column) Nullable() *Column

func (*Column) Primary

func (c *Column) Primary() *Column

func (*Column) References

func (c *Column) References(table, column string) *Column

func (*Column) Unique

func (c *Column) Unique() *Column

type Dialect

type Dialect interface {
	QuoteIdentifier(name string) string
	AutoIncrementDDL() string
}

Dialect interface for schema generation (to avoid circular dependency)

type Executor

type Executor interface {
	Exec(ctx context.Context, sql string, args ...any) (sql.Result, error)
}

Executor interface for executing schema changes

type ForeignKey

type ForeignKey struct {
	Column       string
	RelatedTable string
	RelatedCol   string
}

func (*ForeignKey) References

func (fk *ForeignKey) References(table, column string)

type Index

type Index struct {
	Columns []string
	Name    string
}

type Table

type Table struct {
	Name     string
	Columns  []*Column
	Indices  []Index
	Uniques  []Index
	Foreigns []*ForeignKey
	// contains filtered or unexported fields
}

func (*Table) AddColumn

func (t *Table) AddColumn(name, colType string) *Column

func (*Table) AddIndex

func (t *Table) AddIndex(columns ...string)

func (*Table) AddUniqueIndex

func (t *Table) AddUniqueIndex(columns ...string)

func (*Table) BigInteger

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

func (*Table) Boolean

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

func (*Table) Decimal

func (t *Table) Decimal(name string, precision, scale int) *Column

func (*Table) DropColumn

func (t *Table) DropColumn(name string)

func (*Table) DropIndex

func (t *Table) DropIndex(name string)

func (*Table) Float

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

func (*Table) Foreign

func (t *Table) Foreign(column string) *ForeignKey

func (*Table) ID

func (t *Table) ID()

func (*Table) Integer

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

func (*Table) RenameColumn

func (t *Table) RenameColumn(old, new string)

func (*Table) SoftDeletes

func (t *Table) SoftDeletes()

func (*Table) String

func (t *Table) String(name string, length int) *Column

func (*Table) Text

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

func (*Table) Timestamp

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

func (*Table) Timestamps

func (t *Table) Timestamps()

Jump to

Keyboard shortcuts

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