schema

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnumRegistry = map[string]*ColumnType{}
View Source
var Registry []*TableDef

Functions

This section is empty.

Types

type ColumnDef

type ColumnDef struct {
	Table          string
	Name           string
	Type           *ColumnType
	IsPK           bool
	IsNotNull      bool
	IsUnique       bool
	IsIdentity     bool
	DefaultVal     any
	DefaultExprStr string
	GeneratedExpr  string
	CheckExpr      string
	Collation      string
	RefCol         *ColumnDef
	OnDeleteAction ReferentialAction
	OnUpdateAction ReferentialAction
	HasIndex       bool
}

func Column

func Column(name string, t *ColumnType) *ColumnDef

func (*ColumnDef) Check added in v0.1.3

func (c *ColumnDef) Check(expr string) *ColumnDef

func (*ColumnDef) Collate added in v0.1.3

func (c *ColumnDef) Collate(name string) *ColumnDef

func (*ColumnDef) Default

func (c *ColumnDef) Default(v any) *ColumnDef

func (*ColumnDef) DefaultExpr

func (c *ColumnDef) DefaultExpr(expr string) *ColumnDef

func (*ColumnDef) GeneratedAs added in v0.1.3

func (c *ColumnDef) GeneratedAs(expr string) *ColumnDef

func (*ColumnDef) Identity added in v0.1.3

func (c *ColumnDef) Identity() *ColumnDef

func (*ColumnDef) Index

func (c *ColumnDef) Index() *ColumnDef

func (*ColumnDef) NotNull

func (c *ColumnDef) NotNull() *ColumnDef

func (*ColumnDef) OnDelete

func (c *ColumnDef) OnDelete(a ReferentialAction) *ColumnDef

func (*ColumnDef) OnUpdate

func (c *ColumnDef) OnUpdate(a ReferentialAction) *ColumnDef

func (*ColumnDef) PrimaryKey

func (c *ColumnDef) PrimaryKey() *ColumnDef

func (*ColumnDef) References

func (c *ColumnDef) References(col *ColumnDef) *ColumnDef

func (*ColumnDef) Str

func (c *ColumnDef) Str() string

func (*ColumnDef) String

func (c *ColumnDef) String() string

func (*ColumnDef) Unique

func (c *ColumnDef) Unique() *ColumnDef

type ColumnType

type ColumnType struct {
	SQLType    string
	IsEnum     bool
	EnumName   string
	EnumValues []string
}

func Array added in v0.1.3

func Array(inner *ColumnType) *ColumnType

Array wraps the inner type as a PostgreSQL one-dimensional array, e.g. Array(Int()) renders as INTEGER[].

func BigInt

func BigInt() *ColumnType

func BigSerial

func BigSerial() *ColumnType

func Bool

func Bool() *ColumnType

func Bytea added in v0.1.3

func Bytea() *ColumnType

func Char added in v0.1.3

func Char(length int) *ColumnType

func Date added in v0.1.3

func Date() *ColumnType

func Double added in v0.1.3

func Double() *ColumnType

func Enum

func Enum(name string, values ...string) *ColumnType

func Int

func Int() *ColumnType

func Interval added in v0.1.3

func Interval() *ColumnType

func JSONB

func JSONB() *ColumnType

func Money added in v0.1.3

func Money() *ColumnType

func Numeric

func Numeric(precision, scale int) *ColumnType

func Real added in v0.1.3

func Real() *ColumnType

func Serial

func Serial() *ColumnType

func SmallInt added in v0.1.3

func SmallInt() *ColumnType

func SmallSerial added in v0.1.3

func SmallSerial() *ColumnType

func Text

func Text() *ColumnType

func Time added in v0.1.3

func Time() *ColumnType

func Timestamp

func Timestamp() *ColumnType

func TimestampTZ

func TimestampTZ() *ColumnType

func Timetz added in v0.1.3

func Timetz() *ColumnType

func UUID

func UUID() *ColumnType

func Varchar

func Varchar(length int) *ColumnType

type ConstraintDef added in v0.1.3

type ConstraintDef struct {
	Name string
	Expr string
}

type IndexDef

type IndexDef struct {
	Name      string
	Cols      []string
	Unique    bool
	Predicate string
}

type ReferentialAction

type ReferentialAction string
const (
	Cascade  ReferentialAction = "CASCADE"
	SetNull  ReferentialAction = "SET NULL"
	Restrict ReferentialAction = "RESTRICT"
	NoAction ReferentialAction = "NO ACTION"
)

type TableDef

type TableDef struct {
	Name string
	// contains filtered or unexported fields
}

func Table

func Table(name string, columns ...*ColumnDef) *TableDef

func (*TableDef) Col

func (t *TableDef) Col(name string) *ColumnDef

func (*TableDef) Columns

func (t *TableDef) Columns() []*ColumnDef

func (*TableDef) Constraint added in v0.1.3

func (t *TableDef) Constraint(name, expr string) *TableDef

func (*TableDef) GetConstraints added in v0.1.3

func (t *TableDef) GetConstraints() []ConstraintDef

func (*TableDef) GetIndices

func (t *TableDef) GetIndices() []IndexDef

func (*TableDef) GetUnique added in v0.1.3

func (t *TableDef) GetUnique() []IndexDef

func (*TableDef) Index

func (t *TableDef) Index(name string, cols ...string) *TableDef

func (*TableDef) IndexPartial added in v0.1.3

func (t *TableDef) IndexPartial(name string, cols []string, predicate string) *TableDef

IndexPartial creates an index restricted to rows matching the predicate, e.g. IndexPartial("idx_users_active", []string{"status"}, "status = 'active'").

func (*TableDef) IndexUnique added in v0.1.3

func (t *TableDef) IndexUnique(name string, cols ...string) *TableDef

func (*TableDef) TableName

func (t *TableDef) TableName() string

func (*TableDef) Unique added in v0.1.3

func (t *TableDef) Unique(name string, cols ...string) *TableDef

Jump to

Keyboard shortcuts

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