Help us shape the future of Go! Take the 2026 Go Developer Survey

types

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blueprint

type Blueprint struct {
	Columns   []Column        `json:"columns,omitempty"`
	Indexes   []Index         `json:"indexes,omitempty"`
	Option    BlueprintOption `json:"option,omitempty"`
	Temporary bool            `json:"temporary,omitempty"` // If true, the table will be created as a temporary table (in memory)
}

Blueprint the blueprint of schema

func New

func New() Blueprint

New create a Blueprint

func NewAny

func NewAny(data interface{}) (Blueprint, error)

NewAny create a Blueprint

func NewFile

func NewFile(file string) (Blueprint, error)

NewFile create a Blueprint by File

func NewJSON

func NewJSON(data []byte) (Blueprint, error)

NewJSON create a Blueprint by JSON text

func (Blueprint) ColumnsMapping

func (blueprint Blueprint) ColumnsMapping() map[string]Column

ColumnsMapping get the mapping of columns

func (Blueprint) IndexesMapping

func (blueprint Blueprint) IndexesMapping() map[string]Index

IndexesMapping get the mapping of indexes

type BlueprintOption

type BlueprintOption struct {
	Timestamps  bool `json:"timestamps,omitempty"`   // + created_at, updated_at fields
	SoftDeletes bool `json:"soft_deletes,omitempty"` // + deleted_at field
	Trackings   bool `json:"trackings,omitempty"`    // + created_by, updated_by, deleted_by fields
	Constraints bool `json:"constraints,omitempty"`  // + 约束定义
	Permission  bool `json:"permission,omitempty"`   // + __permission fields
	Logging     bool `json:"logging,omitempty"`      // + __logging_id fields
	Readonly    bool `json:"read_only,omitempty"`    // + Ignore the migrate operation
}

BlueprintOption the blueprint option

type Column

type Column struct {
	Name          string      `json:"name"`
	Label         string      `json:"label,omitempty"`
	Type          string      `json:"type,omitempty"`
	Title         string      `json:"title,omitempty"`
	Description   string      `json:"description,omitempty"`
	Comment       string      `json:"comment,omitempty"`
	Length        int         `json:"length,omitempty"`
	Precision     int         `json:"precision,omitempty"`
	Scale         int         `json:"scale,omitempty"`
	Nullable      bool        `json:"nullable,omitempty"`
	Option        []string    `json:"option,omitempty"`
	Default       interface{} `json:"default,omitempty"`
	DefaultRaw    string      `json:"default_raw,omitempty"`
	Generate      string      `json:"generate,omitempty"` // Increment, UUID,...
	Crypt         string      `json:"crypt,omitempty"`    // AES, PASSWORD, AES-256, AES-128, PASSWORD-HASH, ...
	Index         bool        `json:"index,omitempty"`
	Unique        bool        `json:"unique,omitempty"`
	Primary       bool        `json:"primary,omitempty"`
	Origin        string      `json:"origin,omitempty"`
	RemoveIndex   bool        `json:"-"`
	RemoveUnique  bool        `json:"-"`
	RemovePrimary bool        `json:"-"`
}

Column the field description struct

func NewColumnAny

func NewColumnAny(data interface{}) (Column, error)

NewColumnAny create a Column of Blueprint

func (Column) Hash

func (column Column) Hash() string

Hash get the column hash

type Diff

type Diff struct {
	Columns struct {
		Add []Column
		Del []Column
		Alt []Column
	}
	Indexes struct {
		Add []Index
		Del []Index
		Alt []Index
	}
	Option map[string]bool
}

Diff the different of schema

func Compare

func Compare(blueprint, another Blueprint) (Diff, error)

Compare the two Blueprint, return the difference

func NewDiff

func NewDiff() Diff

NewDiff create a new Diff

func (Diff) Apply

func (diff Diff) Apply(sch Schema, name string) error

Apply apply the changes

func (*Diff) ColumnsDiff

func (diff *Diff) ColumnsDiff(blueprint, another Blueprint)

ColumnsDiff find the column difference

func (*Diff) IndexesDiff

func (diff *Diff) IndexesDiff(blueprint, another Blueprint)

IndexesDiff find the index difference

func (*Diff) OptionDiff

func (diff *Diff) OptionDiff(blueprint, another Blueprint)

OptionDiff find the option difference

type Index

type Index struct {
	Comment string   `json:"comment,omitempty"`
	Name    string   `json:"name,omitempty"`
	Columns []string `json:"columns,omitempty"`
	Type    string   `json:"type,omitempty"` // primary,unique,index,match
	Origin  string   `json:"origin,omitempty"`
}

Index the search index struct

func NewIndexAny

func NewIndexAny(data interface{}) (Index, error)

NewIndexAny create a index of Blueprint

func (Index) Hash

func (index Index) Hash() string

Hash get the index hash

type Schema

type Schema interface {
	SetOption(option interface{}) error

	Close() error
	Create(name string) error
	Drop(name string) error

	Tables(prefix ...string) ([]string, error)
	TableExists(name string) (bool, error)
	TableGet(name string) (Blueprint, error)
	TableCreate(name string, blueprint Blueprint) error
	TableSave(name string, blueprint Blueprint) error
	TableDrop(name string) error
	TableRename(name string, new string) error
	TableDiff(name Blueprint, another Blueprint) (Diff, error)

	ColumnAdd(name string, column Column) error
	ColumnAlt(name string, column Column) error
	ColumnDel(name string, columns ...string) error

	IndexAdd(name string, index Index) error
	IndexAlt(name string, index Index) error
	IndexDel(name string, indexes ...string) error
}

Schema the schema interface

Jump to

Keyboard shortcuts

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