schema

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blueprint

type Blueprint interface {

	// defined in table.go
	Get() *Table
	GetName() string
	GetPrefix() string
	GetFullName() string
	GetColumns() map[string]*Column
	GetIndexes() map[string]*Index

	// defined in column.go
	GetColumn(name string) *Column
	HasColumn(name ...string) bool
	RenameColumn(old string, new string) *Column
	DropColumn(name ...string)

	// defined in primry.go
	GetPrimary() *Primary
	AddPrimary(columnName ...string)
	DropPrimary()

	// defined in index.go
	GetIndex(name string) *Index
	HasIndex(name ...string) bool
	AddIndex(name string, columnNames ...string) *Table
	AddUnique(name string, columnNames ...string) *Table
	AddFulltext(name string, columnNames ...string) *Table
	RenameIndex(old string, new string) *Index
	DropIndex(name ...string)

	// defined in blueprint.go
	// Character types
	String(name string, args ...int) *Column
	Char(name string, args ...int) *Column
	Text(name string) *Column
	MediumText(name string) *Column
	LongText(name string) *Column

	// Binary types
	Binary(name string, args ...int) *Column

	// Date time types
	Date(name string) *Column
	DateTime(name string, args ...int) *Column
	DateTimeTz(name string, args ...int) *Column
	Time(name string, args ...int) *Column
	TimeTz(name string, args ...int) *Column
	Timestamp(name string, args ...int) *Column
	TimestampTz(name string, args ...int) *Column

	// Numberic types
	// @todo: MediumInteger
	TinyInteger(name string) *Column
	UnsignedTinyInteger(name string) *Column
	TinyIncrements(name string) *Column

	SmallInteger(name string) *Column
	UnsignedSmallInteger(name string) *Column
	SmallIncrements(name string) *Column

	Integer(name string) *Column
	UnsignedInteger(name string) *Column
	Increments(name string) *Column

	BigInteger(name string) *Column
	UnsignedBigInteger(name string) *Column
	BigIncrements(name string) *Column
	ID(name string) *Column
	ForeignID(name string) *Column

	Decimal(name string, args ...int) *Column
	UnsignedDecimal(name string, args ...int) *Column

	Float(name string, args ...int) *Column
	UnsignedFloat(name string, args ...int) *Column

	Double(name string, args ...int) *Column
	UnsignedDouble(name string, args ...int) *Column

	// boolean, enum types
	Boolean(name string) *Column
	Enum(name string, option []string) *Column

	// json, jsonb types
	JSON(name string) *Column
	JSONB(name string) *Column

	// uuid, ipAddress, macAddress, year etc.
	// @todo: geometry, geometryCollection, point, multiPoint, polygon, multiPolygon
	UUID(name string) *Column
	IPAddress(name string) *Column
	MACAddress(name string) *Column
	Year(name string) *Column

	// timestamps, timestampsTz,DropTimestamps, DropTimestampsTz, softDeletes, softDeletesTz, DropSoftDeletes, DropSoftDeletesTz
	Timestamps(args ...int) map[string]*Column
	TimestampsTz(args ...int) map[string]*Column
	DropTimestamps()
	DropTimestampsTz()

	SoftDeletes(args ...int) *Column
	SoftDeletesTz(args ...int) *Column
	DropSoftDeletes()
	DropSoftDeletesTz()
}

Blueprint the table operating interface

type Builder

type Builder struct {
	Conn     *Connection
	Mode     string
	Database string
	Schema   string
	dbal.Grammar
}

Builder the table schema builder struct

func (*Builder) AlterTable added in v0.0.3

func (builder *Builder) AlterTable(name string, callback func(table Blueprint)) error

AlterTable alter a table on the schema.

func (*Builder) Builder added in v0.5.1

func (builder *Builder) Builder() *Builder

Builder get the query builder instance

func (*Builder) CreateTable added in v0.0.3

func (builder *Builder) CreateTable(name string, callback func(table Blueprint)) error

CreateTable create a new table on the schema.

func (*Builder) DB added in v0.0.3

func (builder *Builder) DB() *sqlx.DB

DB Alias MustGetDB Get the sqlx DB instance

func (*Builder) DropTable added in v0.0.3

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

DropTable Indicate that the table should be dropped.

func (*Builder) DropTableIfExists added in v0.0.3

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

DropTableIfExists Indicate that the table should be dropped if it exists.

func (*Builder) GetConnection added in v0.0.3

func (builder *Builder) GetConnection() (*dbal.Connection, error)

GetConnection Get the database connection instance.

func (*Builder) GetDB added in v0.0.3

func (builder *Builder) GetDB() (*sqlx.DB, error)

GetDB Get the sqlx DB instance

func (*Builder) GetTable added in v0.0.3

func (builder *Builder) GetTable(name string) (Blueprint, error)

GetTable a table on the schema.

func (*Builder) GetTables added in v0.0.3

func (builder *Builder) GetTables() ([]string, error)

GetTables Get all of the table names for the schema.

func (*Builder) GetVersion added in v0.0.3

func (builder *Builder) GetVersion() (*dbal.Version, error)

GetVersion get the version of the connection database

func (*Builder) HasTable

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

HasTable determine if the given table exists.

func (*Builder) MustAlterTable added in v0.0.3

func (builder *Builder) MustAlterTable(name string, callback func(table Blueprint))

MustAlterTable alter a table on the schema.

func (*Builder) MustCreateTable added in v0.0.3

func (builder *Builder) MustCreateTable(name string, callback func(table Blueprint))

MustCreateTable create a new table on the schema.

func (*Builder) MustDropTable added in v0.0.3

func (builder *Builder) MustDropTable(name string)

MustDropTable Indicate that the table should be dropped.

func (*Builder) MustDropTableIfExists added in v0.0.3

func (builder *Builder) MustDropTableIfExists(name string)

MustDropTableIfExists Indicate that the table should be dropped if it exists.

func (*Builder) MustGetConnection added in v0.0.3

func (builder *Builder) MustGetConnection() *dbal.Connection

MustGetConnection Get the database connection instance.

func (*Builder) MustGetDB added in v0.0.3

func (builder *Builder) MustGetDB() *sqlx.DB

MustGetDB Get the sqlx DB instance

func (*Builder) MustGetTable added in v0.0.3

func (builder *Builder) MustGetTable(name string) Blueprint

MustGetTable a table on the schema.

func (*Builder) MustGetTables added in v0.0.3

func (builder *Builder) MustGetTables() []string

MustGetTables Get all of the table names for the schema.

func (*Builder) MustGetVersion added in v0.0.3

func (builder *Builder) MustGetVersion() *dbal.Version

MustGetVersion get the version of the connection database

func (*Builder) MustHasTable added in v0.0.3

func (builder *Builder) MustHasTable(name string) bool

MustHasTable determine if the given table exists.

func (*Builder) MustRenameTable added in v0.0.3

func (builder *Builder) MustRenameTable(old string, new string) Blueprint

MustRenameTable rename a table on the schema.

func (*Builder) RenameTable added in v0.0.3

func (builder *Builder) RenameTable(old string, new string) error

RenameTable rename a table on the schema.

func (*Builder) SetOption added in v0.0.3

func (builder *Builder) SetOption(option *dbal.Option)

SetOption set the option of connection

type Column

type Column struct {
	*dbal.Column
	Table *Table
}

Column the table column struct

func (*Column) AutoIncrement

func (column *Column) AutoIncrement() *Column

AutoIncrement set the numeric column AutoIncrement attribute is true

func (*Column) HasIndex

func (column *Column) HasIndex(name string) bool

HasIndex check if the column has created the index

func (*Column) Index

func (column *Column) Index() *Column

Index set as index key

func (*Column) NotNull

func (column *Column) NotNull() *Column

NotNull set the column nullable attribute is false

func (*Column) Null

func (column *Column) Null() *Column

Null set the column nullable attribute is true

func (*Column) Primary

func (column *Column) Primary() *Column

Primary set as primary key

func (*Column) SetComment added in v0.0.3

func (column *Column) SetComment(comment string) *Column

SetComment set the column comment to the given value

func (*Column) SetDateTimePrecision added in v0.0.3

func (column *Column) SetDateTimePrecision(precision int) *Column

SetDateTimePrecision set the column precision to the given value

func (*Column) SetDefault added in v0.5.1

func (column *Column) SetDefault(v interface{}) *Column

SetDefault set the column default attribute to the given type name

func (*Column) SetDefaultRaw added in v0.5.1

func (column *Column) SetDefaultRaw(v string) *Column

SetDefaultRaw set the column default raw attribute to the given type name

func (*Column) SetLength added in v0.0.3

func (column *Column) SetLength(length int) *Column

SetLength set the column Length attribute to the given length

func (*Column) SetPrecision added in v0.0.3

func (column *Column) SetPrecision(precision int) *Column

SetPrecision set the column precision to the given value

func (*Column) SetScale added in v0.0.3

func (column *Column) SetScale(scale int) *Column

SetScale set the column scale to the given value

func (*Column) SetType added in v0.0.3

func (column *Column) SetType(typ string) *Column

SetType set the column type attribute to the given type name

func (*Column) Unique

func (column *Column) Unique() *Column

Unique set as index

func (*Column) Unsigned

func (column *Column) Unsigned() *Column

Unsigned set the column IsUnsigned attribute is true

type Connection

type Connection struct {
	Write       *sqlx.DB
	WriteConfig *dbal.Config
	Option      *dbal.Option
	Version     *dbal.Version
}

Connection the database connection for schema operating

type Index

type Index struct {
	*dbal.Index
	Table *Table
}

Index the table index struct

type Primary added in v0.0.3

type Primary struct {
	*dbal.Primary
	Table *Table
}

Primary the table primary key

type Schema

type Schema interface {
	SetOption(option *dbal.Option)

	Builder() *Builder
	GetConnection() (*dbal.Connection, error)
	GetDB() (*sqlx.DB, error)
	GetVersion() (*dbal.Version, error)

	GetTables() ([]string, error)

	GetTable(name string) (Blueprint, error)
	CreateTable(name string, createFunc func(table Blueprint)) error
	DropTable(name string) error
	AlterTable(name string, alterFunc func(table Blueprint)) error
	HasTable(name string) (bool, error)
	RenameTable(old string, new string) error
	DropTableIfExists(name string) error

	MustGetConnection() *dbal.Connection
	MustGetDB() *sqlx.DB
	MustGetVersion() *dbal.Version

	MustGetTables() []string

	MustGetTable(name string) Blueprint
	MustCreateTable(name string, createFunc func(table Blueprint))
	MustDropTable(name string)
	MustAlterTable(name string, alterFunc func(table Blueprint))
	MustHasTable(name string) bool
	MustRenameTable(old string, new string) Blueprint
	MustDropTableIfExists(name string)

	DB() *sqlx.DB // alias MustGetDB
}

Schema The schema interface

func New

func New(driver string, dsn string) Schema

New create a new schema interface using the given driver and DSN

func Use

func Use(conn *Connection) Schema

Use create a new schema interface using the given connection

type Table

type Table struct {
	*dbal.Table
	*Builder
	*Primary
	ColumnMap map[string]*Column
	IndexMap  map[string]*Index
	Name      string
	Prefix    string
}

Table the table struct

func NewTable

func NewTable(name string, builder *Builder) *Table

NewTable create a new blueprint intance

func (*Table) AddFulltext added in v0.5.1

func (table *Table) AddFulltext(key string, columnNames ...string) *Table

AddFulltext Indicate that the given fulltext index should be created.(donthing here)

func (*Table) AddIndex added in v0.0.3

func (table *Table) AddIndex(key string, columnNames ...string) *Table

AddIndex Indicate that the given index should be created.

func (*Table) AddPrimary added in v0.0.3

func (table *Table) AddPrimary(columnNames ...string)

AddPrimary Indicate that the given column should be a primary index.

func (*Table) AddUnique added in v0.0.3

func (table *Table) AddUnique(key string, columnNames ...string) *Table

AddUnique Indicate that the given unique index should be created.

func (*Table) BigIncrements

func (table *Table) BigIncrements(name string) *Column

BigIncrements Create a new auto-incrementing big integer (8-byte) column on the table.

func (*Table) BigInteger

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

BigInteger Create a new auto-incrementing big integer (8-byte) column on the table.

func (*Table) Binary added in v0.0.3

func (table *Table) Binary(name string, args ...int) *Column

Binary Create a new binary column on the table.

func (*Table) Boolean added in v0.0.3

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

Boolean Create a new boolean column on the table.

func (*Table) Char added in v0.0.3

func (table *Table) Char(name string, args ...int) *Column

Char Create a new char column on the table.

func (*Table) Date added in v0.0.3

func (table *Table) Date(name string) *Column

Date Create a new date column on the table.

func (*Table) DateTime added in v0.0.3

func (table *Table) DateTime(name string, args ...int) *Column

DateTime Create a new date-time column on the table.

func (*Table) DateTimeTz added in v0.0.3

func (table *Table) DateTimeTz(name string, args ...int) *Column

DateTimeTz Create a new date-time column (with time zone) on the table.

func (*Table) Decimal added in v0.0.3

func (table *Table) Decimal(name string, args ...int) *Column

Decimal Create a new decimal (16-byte) column on the table.

func (*Table) Double added in v0.0.3

func (table *Table) Double(name string, args ...int) *Column

Double Create a new double (8-byte) column on the table.

func (*Table) DropColumn

func (table *Table) DropColumn(name ...string)

DropColumn Indicate that the given columns should be dropped.

func (*Table) DropIndex

func (table *Table) DropIndex(key ...string)

DropIndex Indicate that the given indexes should be dropped.

func (*Table) DropPrimary

func (table *Table) DropPrimary()

DropPrimary Indicate that dropping the primary index

func (*Table) DropSoftDeletes added in v0.0.3

func (table *Table) DropSoftDeletes()

DropSoftDeletes drop the "deleted_at" timestamp columns.

func (*Table) DropSoftDeletesTz added in v0.0.3

func (table *Table) DropSoftDeletesTz()

DropSoftDeletesTz drop the "deleted_at" timestamp columns.

func (*Table) DropTimestamps added in v0.0.3

func (table *Table) DropTimestamps()

DropTimestamps drop the "created_at", "updated_at" timestamp columns.

func (*Table) DropTimestampsTz added in v0.0.3

func (table *Table) DropTimestampsTz()

DropTimestampsTz drop the "created_at", "updated_at" timestamp columns.

func (*Table) Enum added in v0.0.3

func (table *Table) Enum(name string, option []string) *Column

Enum Create a new enum column on the table.

func (*Table) Float added in v0.0.3

func (table *Table) Float(name string, args ...int) *Column

Float Create a new float (4-byte) column on the table.

func (*Table) ForeignID added in v0.0.3

func (table *Table) ForeignID(name string) *Column

ForeignID Alias UnsignedBigInteger. Create a new unsigned big integer (8-byte) column on the table.

func (*Table) Get added in v0.0.3

func (table *Table) Get() *Table

Get Get the DBAL table instance

func (*Table) GetColumn

func (table *Table) GetColumn(name string) *Column

GetColumn get the column instance of the table, if the column does not exist return nil.

func (*Table) GetColumns

func (table *Table) GetColumns() map[string]*Column

GetColumns Get the columns map of the table

func (*Table) GetFullName added in v0.0.3

func (table *Table) GetFullName() string

GetFullName get the table name with prefix

func (*Table) GetIndex

func (table *Table) GetIndex(name string) *Index

GetIndex get the index instance for the given name,if the index does not exist return nil.

func (*Table) GetIndexes

func (table *Table) GetIndexes() map[string]*Index

GetIndexes Get the indexes map of the table

func (*Table) GetName

func (table *Table) GetName() string

GetName get the table name

func (*Table) GetPrefix added in v0.0.3

func (table *Table) GetPrefix() string

GetPrefix get the table prefix

func (*Table) GetPrimary added in v0.0.3

func (table *Table) GetPrimary() *Primary

GetPrimary get the table primary key instance

func (*Table) HasColumn

func (table *Table) HasColumn(name ...string) bool

HasColumn Determine if the table has a given column.

func (*Table) HasIndex

func (table *Table) HasIndex(name ...string) bool

HasIndex Determine if the table has a given index.

func (*Table) ID

func (table *Table) ID(name string) *Column

ID Alias BigIncrements. Create a new auto-incrementing big integer (8-byte) column on the table.

func (*Table) IPAddress added in v0.0.3

func (table *Table) IPAddress(name string) *Column

IPAddress Create a new IP address ( integer 4-byte ) column on the table.

func (*Table) Increments added in v0.0.3

func (table *Table) Increments(name string) *Column

Increments Create a new auto-incrementing big integer (2-byte) column on the table.

func (*Table) Integer added in v0.0.3

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

Integer Create a new integer (4-byte) column on the table.

func (*Table) JSON added in v0.0.3

func (table *Table) JSON(name string) *Column

JSON Create a new json column on the table.

func (*Table) JSONB added in v0.0.3

func (table *Table) JSONB(name string) *Column

JSONB Create a new jsonb column on the table.

func (*Table) LongText added in v0.0.3

func (table *Table) LongText(name string) *Column

LongText Create a new long text column on the table.

func (*Table) MACAddress added in v0.0.3

func (table *Table) MACAddress(name string) *Column

MACAddress Create a new MAC address column on the table.

func (*Table) MediumText added in v0.0.3

func (table *Table) MediumText(name string) *Column

MediumText Create a new medium text column on the table.

func (*Table) RenameColumn

func (table *Table) RenameColumn(old string, new string) *Column

RenameColumn Indicate that the given column should be renamed.

func (*Table) RenameIndex

func (table *Table) RenameIndex(old string, new string) *Index

RenameIndex Indicate that the given indexes should be renamed.

func (*Table) SmallIncrements added in v0.0.3

func (table *Table) SmallIncrements(name string) *Column

SmallIncrements Create a new auto-incrementing small integer (2-byte) column on the table.

func (*Table) SmallInteger added in v0.0.3

func (table *Table) SmallInteger(name string) *Column

SmallInteger Create a new small integer (2-byte) column on the table.

func (*Table) SoftDeletes added in v0.0.3

func (table *Table) SoftDeletes(args ...int) *Column

SoftDeletes Add a "deleted_at" timestamp for the table.

func (*Table) SoftDeletesTz added in v0.0.3

func (table *Table) SoftDeletesTz(args ...int) *Column

SoftDeletesTz Add a "deleted_at" timestampTz for the table.

func (*Table) String

func (table *Table) String(name string, args ...int) *Column

String Create a new string column on the table.

func (*Table) Text added in v0.0.3

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

Text Create a new text column on the table.

func (*Table) Time added in v0.0.3

func (table *Table) Time(name string, args ...int) *Column

Time Create a new time column on the table.

func (*Table) TimeTz added in v0.0.3

func (table *Table) TimeTz(name string, args ...int) *Column

TimeTz Create a new time column (with time zone) on the table.

func (*Table) Timestamp added in v0.0.3

func (table *Table) Timestamp(name string, args ...int) *Column

Timestamp Create a new timestamp column on the table.

func (*Table) TimestampTz added in v0.0.3

func (table *Table) TimestampTz(name string, args ...int) *Column

TimestampTz Create a new timestamp (with time zone) column on the table.

func (*Table) Timestamps added in v0.0.3

func (table *Table) Timestamps(args ...int) map[string]*Column

Timestamps Add nullable creation and update timestamps to the table.

func (*Table) TimestampsTz added in v0.0.3

func (table *Table) TimestampsTz(args ...int) map[string]*Column

TimestampsTz Add creation and update timestampTz columns to the table.

func (*Table) TinyIncrements added in v0.0.3

func (table *Table) TinyIncrements(name string) *Column

TinyIncrements Create a new auto-incrementing tiny integer (1-byte) column on the table.

func (*Table) TinyInteger added in v0.0.3

func (table *Table) TinyInteger(name string) *Column

TinyInteger Create a new tiny integer (1-byte) column on the table.

func (*Table) UUID added in v0.0.3

func (table *Table) UUID(name string) *Column

UUID Create a new uuid column on the table.

func (*Table) UnsignedBigInteger

func (table *Table) UnsignedBigInteger(name string) *Column

UnsignedBigInteger Create a new unsigned big integer (8-byte) column on the table.

func (*Table) UnsignedDecimal added in v0.0.3

func (table *Table) UnsignedDecimal(name string, args ...int) *Column

UnsignedDecimal Create a new unsigned decimal (16-byte) column on the table.

func (*Table) UnsignedDouble added in v0.0.3

func (table *Table) UnsignedDouble(name string, args ...int) *Column

UnsignedDouble Create a new unsigned double (8-byte) column on the table.

func (*Table) UnsignedFloat added in v0.0.3

func (table *Table) UnsignedFloat(name string, args ...int) *Column

UnsignedFloat Create a new unsigned float (4-byte) column on the table.

func (*Table) UnsignedInteger added in v0.0.3

func (table *Table) UnsignedInteger(name string) *Column

UnsignedInteger Create a new auto-incrementing integer (4-byte) column on the table.

func (*Table) UnsignedSmallInteger added in v0.0.3

func (table *Table) UnsignedSmallInteger(name string) *Column

UnsignedSmallInteger Create a new unsigned small integer (2-byte) column on the table.

func (*Table) UnsignedTinyInteger added in v0.0.3

func (table *Table) UnsignedTinyInteger(name string) *Column

UnsignedTinyInteger Create a new auto-incrementing tiny integer (1-byte) column on the table.

func (*Table) Year added in v0.0.3

func (table *Table) Year(name string) *Column

Year Create a new year column on the table.

Jump to

Keyboard shortcuts

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