schema

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_VARCHAR_SIZE = 200
)

Variables

View Source
var (
	MysqlSchemaDialect    = NewMysqlSchemaDialect()
	SqliteSchemaDialect   = NewSqliteSchemaDialect()
	PostgresSchemaDialect = NewPostgresSchemaDialect()
)
View Source
var (
	INTEGER   = &IntegerFieldType{}
	BIGINT    = &BigIntFieldType{}
	VARCHAR   = &VarcharFieldType{}
	BOOLEAN   = &BooleanFieldType{}
	REAL      = &RealFieldType{}
	BLOB      = &BlobFieldType{}
	DATETIME  = &DateTimeFieldType{}
	TIMESTAMP = &TimeStampFieldType{}
	CREATED   = &CreatedFieldType{}
	UPDATED   = &UpdatedFieldType{}
)
View Source
var (
	AUTO_INCREMENT = &AutoIncrementKeyword{}
	PRIMARY_KEY    = &PrimaryKeyKeyword{}
	INDEX          = &IndexKeyword{}
	UNIQUE_INDEX   = &UniqueIndexKeyword{}
	NULL           = &NullKeyword{}
	NOT_NULL       = &NotNullKeyword{}
	DEFAULT        = &DefaultKeyword{}
)

List of vendor-specific keywords

Functions

func GenerateSchema

func GenerateSchema(schemaDialect SchemaDialect, t *Table) string

func GenerateSchemaCreateIndex

func GenerateSchemaCreateIndex(schemaDialect SchemaDialect, table *Table, index *Index) string

func GenerateSchemaCreateTable

func GenerateSchemaCreateTable(schemaDialect SchemaDialect, table *Table) string

Types

type AutoIncrementKeyword

type AutoIncrementKeyword struct{}

func (*AutoIncrementKeyword) Accept

func (a *AutoIncrementKeyword) Accept(visitor ShemaKeywordVisitor)

type BigIntFieldType added in v0.0.5

type BigIntFieldType struct{}

func (*BigIntFieldType) Accept added in v0.0.5

func (b *BigIntFieldType) Accept(visitor FieldTypeVisitor)

type BlobFieldType

type BlobFieldType struct{}

func (*BlobFieldType) Accept

func (b *BlobFieldType) Accept(visitor FieldTypeVisitor)

type BooleanFieldType

type BooleanFieldType struct{}

func (*BooleanFieldType) Accept

func (b *BooleanFieldType) Accept(visitor FieldTypeVisitor)

type ConditionalStringSliceAppender

type ConditionalStringSliceAppender struct {
	// contains filtered or unexported fields
}

func (*ConditionalStringSliceAppender) Append

func (c *ConditionalStringSliceAppender) Append(s ...string)

func (*ConditionalStringSliceAppender) AppendWithCondition

func (c *ConditionalStringSliceAppender) AppendWithCondition(condition bool, s ...string)

func (*ConditionalStringSliceAppender) Slice

type CreatedFieldType

type CreatedFieldType struct{}

func (*CreatedFieldType) Accept

func (c *CreatedFieldType) Accept(visitor FieldTypeVisitor)

type DateTimeFieldType

type DateTimeFieldType struct{}

func (*DateTimeFieldType) Accept

func (d *DateTimeFieldType) Accept(visitor FieldTypeVisitor)

type DefaultKeyword

type DefaultKeyword struct{}

func (*DefaultKeyword) Accept

func (d *DefaultKeyword) Accept(visitor ShemaKeywordVisitor)

type DialectVisitor

type DialectVisitor interface {
	VisitMysql(*mysql)
	VisitSqlite(*sqlite)
	VisitPostgres(*postgres)
}

type Field

type Field struct {
	Name     string
	Type     FieldType
	Primary  bool
	Auto     bool
	Size     int
	Nullable bool
	Default  string
}

type FieldType

type FieldType interface {
	Accept(FieldTypeVisitor)
}

func GoToFieldType

func GoToFieldType(goType string) (FieldType, error)

type FieldTypeVisitor

type FieldTypeVisitor interface {
	VisitInteger(*IntegerFieldType)
	VisitBigInt(*BigIntFieldType)
	VisitVarchar(*VarcharFieldType)
	VisitBoolean(*BooleanFieldType)
	VisitReal(*RealFieldType)
	VisitBlob(*BlobFieldType)
	VisitDateTime(*DateTimeFieldType)
	VisitTimeStamp(*TimeStampFieldType)
	VisitCreated(*CreatedFieldType)
	VisitUpdated(*UpdatedFieldType)
}

type Index

type Index struct {
	Name   string
	Unique bool

	Fields []*Field
}

type IndexKeyword

type IndexKeyword struct{}

func (*IndexKeyword) Accept

func (i *IndexKeyword) Accept(visitor ShemaKeywordVisitor)

type IntegerFieldType

type IntegerFieldType struct{}

func (*IntegerFieldType) Accept

func (i *IntegerFieldType) Accept(visitor FieldTypeVisitor)

type NotNullKeyword

type NotNullKeyword struct{}

func (*NotNullKeyword) Accept

func (n *NotNullKeyword) Accept(visitor ShemaKeywordVisitor)

type NullKeyword

type NullKeyword struct{}

func (*NullKeyword) Accept

func (n *NullKeyword) Accept(visitor ShemaKeywordVisitor)

type PrimaryKeyKeyword

type PrimaryKeyKeyword struct{}

func (*PrimaryKeyKeyword) Accept

func (p *PrimaryKeyKeyword) Accept(visitor ShemaKeywordVisitor)

type RealFieldType

type RealFieldType struct{}

func (*RealFieldType) Accept

func (r *RealFieldType) Accept(visitor FieldTypeVisitor)

type SchemaDialect

type SchemaDialect interface {
	databases.Dialect
	Accept(DialectVisitor)
	IndexNameFromFieldNames(fieldNames ...string) (string, error)
}

func NewMysqlSchemaDialect

func NewMysqlSchemaDialect() SchemaDialect

func NewPostgresSchemaDialect

func NewPostgresSchemaDialect() SchemaDialect

func NewSqliteSchemaDialect

func NewSqliteSchemaDialect() SchemaDialect

func ParseSchemaDialectFromString

func ParseSchemaDialectFromString(dialectStr string) SchemaDialect

type SchemaKeyword

type SchemaKeyword interface {
	Accept(ShemaKeywordVisitor)
}

type ShemaKeywordVisitor

type ShemaKeywordVisitor interface {
	VisitAutoIncrement(*AutoIncrementKeyword)
	VisitPrimaryKey(*PrimaryKeyKeyword)
	VisitIndex(*IndexKeyword)
	VisitUniqueIndex(*UniqueIndexKeyword)
	VisitNull(*NullKeyword)
	VisitNotNull(*NotNullKeyword)
	VisitDefault(*DefaultKeyword)
}

type Table

type Table struct {
	Name string

	Fields  []*Field
	Indexes []*Index
	Primary []*Field
}

type TableBuilder

type TableBuilder interface {
	Field(name string, fieldType FieldType, primary, auto bool, size int) TableBuilder
	FieldWithDefault(name string, fieldType FieldType, primary, auto bool, size int, defaultValue string) TableBuilder
	NullableField(name string, fieldType FieldType, size int) TableBuilder
	Primary(fieldNames ...string) TableBuilder
	Index(name string, unique bool, fieldNames ...string) TableBuilder

	Build() *Table
}

func NewTableBuilder

func NewTableBuilder(tableName string) TableBuilder

type TimeStampFieldType

type TimeStampFieldType struct{}

func (*TimeStampFieldType) Accept

func (t *TimeStampFieldType) Accept(visitor FieldTypeVisitor)

type UniqueIndexKeyword

type UniqueIndexKeyword struct{}

func (*UniqueIndexKeyword) Accept

func (u *UniqueIndexKeyword) Accept(visitor ShemaKeywordVisitor)

type UpdatedFieldType

type UpdatedFieldType struct{}

func (*UpdatedFieldType) Accept

func (u *UpdatedFieldType) Accept(visitor FieldTypeVisitor)

type VarcharFieldType

type VarcharFieldType struct{}

func (*VarcharFieldType) Accept

func (v *VarcharFieldType) Accept(visitor FieldTypeVisitor)

Jump to

Keyboard shortcuts

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