model

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnContainer

type ColumnContainer interface {
	AddColumns(...IndexColumn)
	Columns() chan IndexColumn
}

ColumnContainer is the interface for objects that can contain column names

type ColumnType

type ColumnType int

ColumnType describes the possible types that a column may take

const (
	ColumnTypeInvalid ColumnType = iota
	ColumnTypeBit
	ColumnTypeTinyInt
	ColumnTypeSmallInt
	ColumnTypeMediumInt
	ColumnTypeInt
	ColumnTypeInteger
	ColumnTypeBigInt
	ColumnTypeReal
	ColumnTypeDouble
	ColumnTypeFloat
	ColumnTypeDecimal
	ColumnTypeNumeric
	ColumnTypeDate
	ColumnTypeTime
	ColumnTypeTimestamp
	ColumnTypeDateTime
	ColumnTypeYear
	ColumnTypeChar
	ColumnTypeVarChar
	ColumnTypeBinary
	ColumnTypeVarBinary
	ColumnTypeTinyBlob
	ColumnTypeBlob
	ColumnTypeMediumBlob
	ColumnTypeLongBlob
	ColumnTypeTinyText
	ColumnTypeText
	ColumnTypeMediumText
	ColumnTypeLongText

	ColumnTypeMax
)

List of possible ColumnType values

func (ColumnType) String

func (c ColumnType) String() string

func (ColumnType) SynonymType added in v0.0.7

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 interface {
	Stmt

	Name() string
	IsIfNotExists() bool
	SetIfNotExists(bool) Database
	// contains filtered or unexported methods
}

Database represents a database definition

func NewDatabase

func NewDatabase(n string) Database

NewDatabase creates a new database mode with th given name

type Index

type Index interface {
	Stmt
	ColumnContainer

	HasName() bool
	HasSymbol() bool
	Name() string
	Reference() Reference
	SetReference(Reference) Index
	SetSymbol(string) Index
	SetType(IndexType) Index
	SetName(string) Index
	Symbol() string
	IsBtree() bool
	IsHash() bool
	IsPrimaryKey() bool
	IsNormal() bool
	IsUnique() bool
	IsFullText() bool
	IsSpatial() bool
	IsForeginKey() bool

	// Normalize returns normalized index. If a normalization was performed
	// and the index is modified, returns a new instance of the Table object
	// along with a true value as the second return value.
	// Otherwise, Normalize() returns the receiver unchanged, with a false
	// as the second return value.
	Normalize() (Index, bool)

	// Clone returns the clone index
	Clone() Index
}

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.

type IndexColumn added in v0.0.8

type IndexColumn interface {
	ID() string
	Name() string
	SetLength(string) IndexColumn
	HasLength() bool
	Length() string
}

IndexColumn is a column name/length specification used in indexes

func NewIndexColumn added in v0.0.8

func NewIndexColumn(name string) IndexColumn

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 added in v0.0.8

func (i IndexKind) String() 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 added in v0.0.8

func (i IndexType) String() string

type Length

type Length interface {
	HasDecimal() bool
	Decimal() string
	SetDecimal(string) Length
	Length() string
}

Length describes the possible length constraint of a column

func NewLength

func NewLength(v string) Length

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

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 interface {
	ColumnContainer

	ID() string
	String() string
	TableName() string
	OnDelete() ReferenceOption
	OnUpdate() ReferenceOption
	SetTableName(string) Reference
	SetMatch(ReferenceMatch) Reference
	SetOnDelete(ReferenceOption) Reference
	SetOnUpdate(ReferenceOption) Reference
	MatchFull() bool
	MatchPartial() bool
	MatchSimple() bool
}

Reference describes a possible reference from one table to another

func NewReference

func NewReference() Reference

NewReference creates a reference constraint

type ReferenceMatch

type ReferenceMatch int

ReferenceMatch describes the mathing method of a reference

const (
	ReferenceMatchNone ReferenceMatch = iota
	ReferenceMatchFull
	ReferenceMatchPartial
	ReferenceMatchSimple
)

List of possible ReferenceMatch values

func (ReferenceMatch) String added in v0.0.8

func (i ReferenceMatch) String() string

type ReferenceOption

type ReferenceOption int

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

const (
	ReferenceOptionNone ReferenceOption = iota
	ReferenceOptionRestrict
	ReferenceOptionCascade
	ReferenceOptionSetNull
	ReferenceOptionNoAction
)

List of possible ReferenceOption values

func (ReferenceOption) String added in v0.0.8

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 interface {
	Stmt

	Name() string
	IsTemporary() bool
	SetTemporary(bool) Table
	IsIfNotExists() bool
	SetIfNotExists(bool) Table

	HasLikeTable() bool
	LikeTable() string
	SetLikeTable(string) Table

	AddColumn(TableColumn) Table
	Columns() chan TableColumn
	AddIndex(Index) Table
	Indexes() chan Index
	AddOption(TableOption) Table
	Options() chan TableOption

	LookupColumn(string) (TableColumn, bool)
	LookupIndex(string) (Index, bool)

	// Normalize returns normalized table. If a normalization was performed
	// and the table is modified, returns a new instance of the Table object
	// along with a true value as the second return value.
	// Otherwise, Normalize() returns the receiver unchanged, with a false
	// as the second return value.
	Normalize() (Table, bool)
}

Table describes a table model

func NewTable

func NewTable(name string) Table

NewTable create a new table with the given name

type TableColumn

type TableColumn interface {
	Stmt

	TableID() string
	SetTableID(string) TableColumn

	Name() string
	Type() ColumnType
	SetType(ColumnType) TableColumn

	HasLength() bool
	Length() Length
	SetLength(Length) TableColumn
	HasCharacterSet() bool
	CharacterSet() string
	SetCharacterSet(string) TableColumn
	HasCollation() bool
	Collation() string
	HasDefault() bool
	Default() string
	IsQuotedDefault() bool
	SetDefault(string, bool) TableColumn
	HasComment() bool
	Comment() string
	SetComment(string) TableColumn
	HasAutoUpdate() bool
	AutoUpdate() string
	SetAutoUpdate(string) TableColumn

	NullState() NullState
	SetNullState(NullState) TableColumn

	IsAutoIncrement() bool
	SetAutoIncrement(bool) TableColumn
	IsBinary() bool
	SetBinary(bool) TableColumn
	IsKey() bool
	SetKey(bool) TableColumn
	IsPrimary() bool
	SetPrimary(bool) TableColumn
	IsUnique() bool
	SetUnique(bool) TableColumn
	IsUnsigned() bool
	SetUnsigned(bool) TableColumn
	IsZeroFill() bool
	SetZeroFill(bool) TableColumn

	// NativeLength returns the "native" size of a column type. This is the length used if you do not explicitly specify it.
	// Currently only supports numeric types, but may change later.
	NativeLength() Length

	// Normalize returns normalized column. If a normalization was performed
	// and the column is modified, returns a new instance of the Table object
	// along with a true value as the second return value.
	// Otherwise, Normalize() returns the receiver unchanged, with a false
	// as the second return value.
	//
	// Normalization is performed on numertic type display lengths, synonym
	// types, and NULL expressions
	Normalize() (TableColumn, bool)

	// Clone returns the cloned column
	Clone() TableColumn
}

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

type TableOption

type TableOption interface {
	Stmt
	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

Jump to

Keyboard shortcuts

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