model

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 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 ColumnType

type ColumnType int

ColumnType describes the possible types that a column may take

const (
	ColumnTypeInvalid ColumnType = iota
	ColumnTypeBigInt
	ColumnTypeBinary
	ColumnTypeBit
	ColumnTypeBlob
	ColumnTypeBool
	ColumnTypeBoolean
	ColumnTypeChar
	ColumnTypeDate
	ColumnTypeDateTime
	ColumnTypeDecimal
	ColumnTypeDouble
	ColumnTypeEnum
	ColumnTypeFloat
	ColumnTypeGeometry
	ColumnTypeGeometryCollection
	ColumnTypeInt
	ColumnTypeInteger
	ColumnTypeJSON
	ColumnTypeLineString
	ColumnTypeLongBlob
	ColumnTypeLongText
	ColumnTypeMediumBlob
	ColumnTypeMediumInt
	ColumnTypeMediumText
	ColumnTypeMultiLineString
	ColumnTypeMultiPoint
	ColumnTypeMultiPolygon
	ColumnTypeNumeric
	ColumnTypePoint
	ColumnTypePolygon
	ColumnTypeReal
	ColumnTypeSet
	ColumnTypeSmallInt
	ColumnTypeText
	ColumnTypeTime
	ColumnTypeTimestamp
	ColumnTypeTinyBlob
	ColumnTypeTinyInt
	ColumnTypeTinyText
	ColumnTypeVarBinary
	ColumnTypeVarChar
	ColumnTypeYear

	ColumnTypeMax
)

List of possible ColumnType values

func (ColumnType) String

func (c ColumnType) String() string

func (ColumnType) SynonymType

func (c ColumnType) SynonymType() ColumnType

SynonymType returns synonym for a given type. If the type does not have a synonym then this method returns the receiver itself

type Database

type Database struct {
	Name        Ident
	IfNotExists bool
}

Database represents a database definition

func NewDatabase

func NewDatabase(name Ident) *Database

NewDatabase creates a new database mode with th given name

func (*Database) ID added in v0.0.5

func (d *Database) ID() string

type DefaultValue added in v0.0.5

type DefaultValue struct {
	Valid  bool
	Value  string
	Quoted bool
}

type Ident added in v0.0.5

type Ident string

Ident is a string for use as identifiers such as table and column names. It should be quoted to avoid confusion with reserved words.

func (Ident) Quoted added in v0.0.5

func (ident Ident) Quoted() string

type Index

type Index struct {
	Table          string
	Type           IndexType
	ConstraintName MaybeIdent
	Kind           IndexKind
	Name           MaybeIdent
	Columns        []*IndexColumn
	Reference      *Reference
	Options        []*IndexOption
}

Index describes an index on a table.

func NewIndex

func NewIndex(kind IndexKind, table string) *Index

NewIndex creates a new index with the given index kind.

func (*Index) ID added in v0.0.5

func (idx *Index) ID() string

func (*Index) Normalize

func (stmt *Index) Normalize() *Index

type IndexColumn

type IndexColumn struct {
	Name          Ident
	Length        MaybeString
	SortDirection IndexColumnSortDirection
}

IndexColumn is a column name/length specification used in indexes

func NewIndexColumn

func NewIndexColumn(name Ident) *IndexColumn

func (*IndexColumn) ID

func (col *IndexColumn) ID() string

type IndexColumnSortDirection

type IndexColumnSortDirection int
const (
	SortDirectionNone IndexColumnSortDirection = iota
	SortDirectionAscending
	SortDirectionDescending
)

type IndexKind

type IndexKind int

IndexKind describes the kind (purpose) of an index

const (
	IndexKindInvalid IndexKind = iota
	IndexKindPrimaryKey
	IndexKindNormal
	IndexKindUnique
	IndexKindFullText
	IndexKindSpatial
	IndexKindForeignKey
)

List of possible IndexKind.

func (IndexKind) String

func (i IndexKind) String() string

type IndexOption

type IndexOption struct {
	Key        string
	Value      string
	NeedQuotes bool
}

IndexOption describes a possible index option, such as `WITH PARSER ngram`

func NewIndexOption

func NewIndexOption(k, v string, q bool) *IndexOption

func (*IndexOption) ID added in v0.0.5

func (opt *IndexOption) ID() string

type IndexType

type IndexType int

IndexType describes the type (algorithm) used by the index.

const (
	IndexTypeNone IndexType = iota
	IndexTypeBtree
	IndexTypeHash
)

List of possible index types

func (IndexType) String

func (i IndexType) String() string

type Length

type Length struct {
	Decimals MaybeString
	Length   string
}

func NewLength

func NewLength(v string) *Length

NewLength creates a new Length which describes the length of a column

type MaybeIdent added in v0.0.5

type MaybeIdent struct {
	Ident
	Valid bool
}

MaybeIdent is an Ident that may not be set.

type MaybeInteger added in v0.0.8

type MaybeInteger struct {
	Valid bool
	Value int64
}

MaybeInteger is an integer that may not be set.

type MaybeString added in v0.0.5

type MaybeString struct {
	Valid bool
	Value string
}

MaybeString is a string that may not be set.

type NullState

type NullState int

NullState describes the possible NULL constraint of a column

const (
	NullStateNone NullState = iota
	NullStateNull
	NullStateNotNull
)

List of possible NullStates. NullStateNone specifies that there is no NULL constraint. NullStateNull explicitly specifies that the column may be NULL. NullStateNotNull specifies that the column may not be NULL

type Reference

type Reference struct {
	TableName Ident
	Columns   []*IndexColumn
	Match     ReferenceMatch
	OnDelete  ReferenceOption
	OnUpdate  ReferenceOption
}

Reference describes a possible reference from one table to another

func NewReference

func NewReference() *Reference

NewReference creates a reference constraint

func (*Reference) ID

func (r *Reference) ID() string

type ReferenceMatch

type ReferenceMatch int

ReferenceMatch describes the matching method of a reference

const (
	ReferenceMatchNone ReferenceMatch = iota
	ReferenceMatchFull
	ReferenceMatchPartial
	ReferenceMatchSimple
)

List of possible ReferenceMatch values

func (ReferenceMatch) String

func (i ReferenceMatch) String() string

type ReferenceOption

type ReferenceOption int

ReferenceOption describes the actions that could be taken when a table/column referred by the reference has been deleted

const (
	ReferenceOptionNone ReferenceOption = iota
	ReferenceOptionRestrict
	ReferenceOptionCascade
	ReferenceOptionSetNull
	ReferenceOptionNoAction
)

List of possible ReferenceOption values

func (ReferenceOption) String

func (i ReferenceOption) String() string

type Stmt

type Stmt interface {
	ID() string
}

Stmt is the interface to define a statement

type Stmts

type Stmts []Stmt

Stmts describes a list of statements

func (Stmts) Lookup

func (s Stmts) Lookup(id string) (Stmt, bool)

Lookup looks for a statement with the given ID

type Table

type Table struct {
	Name        Ident
	Temporary   bool
	IfNotExists bool
	LikeTable   MaybeIdent
	Columns     []*TableColumn
	Indexes     []*Index
	Options     []*TableOption
}

Table describes a table model

func NewTable

func NewTable(name Ident) *Table

NewTable create a new table with the given name

func (*Table) ID added in v0.0.5

func (t *Table) ID() string

func (*Table) LookupColumn

func (t *Table) LookupColumn(id string) (*TableColumn, bool)

func (*Table) LookupColumnBefore

func (t *Table) LookupColumnBefore(id string) (*TableColumn, bool)

func (*Table) LookupColumnOrder

func (t *Table) LookupColumnOrder(id string) (int, bool)

func (*Table) LookupIndex

func (t *Table) LookupIndex(id string) (*Index, bool)

func (*Table) Normalize

func (t *Table) Normalize() *Table

type TableColumn

type TableColumn struct {
	TableID       string
	Name          Ident
	Type          ColumnType
	Length        *Length
	NullState     NullState
	CharacterSet  MaybeIdent
	Collation     MaybeIdent
	Default       DefaultValue
	Comment       MaybeString
	AutoUpdate    MaybeString
	EnumValues    []string
	SetValues     []string
	AutoIncrement bool
	Binary        bool
	Key           bool
	Primary       bool
	Unique        bool
	Unsigned      bool
	ZeroFill      bool
	SRID          MaybeInteger
}

TableColumn describes a model object that describes a column definition of a table

func NewTableColumn

func NewTableColumn(name string) *TableColumn

NewTableColumn creates a new TableColumn with the given name

func (*TableColumn) ID added in v0.0.5

func (t *TableColumn) ID() string

func (*TableColumn) NativeLength

func (t *TableColumn) NativeLength() *Length

func (*TableColumn) Normalize

func (t *TableColumn) Normalize() *TableColumn

type TableOption

type TableOption struct {
	Key        string
	Value      string
	NeedQuotes bool
}

TableOption describes a possible table option, such as `ENGINE=InnoDB`

func NewTableOption

func NewTableOption(k, v string, q bool) *TableOption

NewTableOption creates a new table option with the given name, value, and a flag indicating if quoting is necessary

func (*TableOption) ID added in v0.0.5

func (opt *TableOption) ID() string

Jump to

Keyboard shortcuts

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