Documentation ¶
Index ¶
- type BuildIndexOptionsInterface
- type ColumnType
- func (ct ColumnType) AutoIncrement() (isAutoIncrement bool, ok bool)
- func (ct ColumnType) ColumnType() (columnType string, ok bool)
- func (ct ColumnType) Comment() (value string, ok bool)
- func (ct ColumnType) DatabaseTypeName() string
- func (ct ColumnType) DecimalSize() (precision int64, scale int64, ok bool)
- func (ct ColumnType) DefaultValue() (value string, ok bool)
- func (ct ColumnType) Length() (length int64, ok bool)
- func (ct ColumnType) Name() string
- func (ct ColumnType) Nullable() (nullable bool, ok bool)
- func (ct ColumnType) PrimaryKey() (isPrimaryKey bool, ok bool)
- func (ct ColumnType) ScanType() reflect.Type
- func (ct ColumnType) Unique() (unique bool, ok bool)
- type Config
- type GormDataTypeInterface
- type Index
- type Migrator
- func (m Migrator) AddColumn(value interface{}, name string) error
- func (m Migrator) AlterColumn(value interface{}, field string) error
- func (m Migrator) AutoMigrate(values ...interface{}) error
- func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{})
- func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)
- func (m Migrator) CreateConstraint(value interface{}, name string) error
- func (m Migrator) CreateIndex(value interface{}, name string) error
- func (m Migrator) CreateTable(values ...interface{}) error
- func (m Migrator) CreateView(name string, option gorm.ViewOption) error
- func (m Migrator) CurrentDatabase() (name string)
- func (m Migrator) CurrentTable(stmt *gorm.Statement) interface{}
- func (m Migrator) DataTypeOf(field *schema.Field) string
- func (m Migrator) DropColumn(value interface{}, name string) error
- func (m Migrator) DropConstraint(value interface{}, name string) error
- func (m Migrator) DropIndex(value interface{}, name string) error
- func (m Migrator) DropTable(values ...interface{}) error
- func (m Migrator) DropView(name string) error
- func (m Migrator) FullDataTypeOf(field *schema.Field) (expr clause.Expr)
- func (m Migrator) GetIndexes(dst interface{}) ([]gorm.Index, error)
- func (m Migrator) GetTables() (tableList []string, err error)
- func (m Migrator) GetTypeAliases(databaseTypeName string) []string
- func (m Migrator) GuessConstraintAndTable(stmt *gorm.Statement, name string) (_ *schema.Constraint, _ *schema.Check, table string)
- func (m Migrator) HasColumn(value interface{}, field string) bool
- func (m Migrator) HasConstraint(value interface{}, name string) bool
- func (m Migrator) HasIndex(value interface{}, name string) bool
- func (m Migrator) HasTable(value interface{}) bool
- func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnType gorm.ColumnType) error
- func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error
- func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
- func (m Migrator) RenameTable(oldName, newName interface{}) error
- func (m Migrator) ReorderModels(values []interface{}, autoAdd bool) (results []interface{})
- func (m Migrator) RunWithValue(value interface{}, fc func(*gorm.Statement) error) error
- func (m Migrator) TableType(dst interface{}) (gorm.TableType, error)
- type TableType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildIndexOptionsInterface ¶
type BuildIndexOptionsInterface interface {
BuildIndexOptions([]schema.IndexOption, *gorm.Statement) []interface{}
}
BuildIndexOptionsInterface build index options interface
type ColumnType ¶
type ColumnType struct { SQLColumnType *sql.ColumnType NameValue sql.NullString DataTypeValue sql.NullString ColumnTypeValue sql.NullString PrimaryKeyValue sql.NullBool UniqueValue sql.NullBool AutoIncrementValue sql.NullBool LengthValue sql.NullInt64 DecimalSizeValue sql.NullInt64 ScaleValue sql.NullInt64 NullableValue sql.NullBool ScanTypeValue reflect.Type CommentValue sql.NullString DefaultValueValue sql.NullString }
ColumnType column type implements ColumnType interface
func (ColumnType) AutoIncrement ¶
func (ct ColumnType) AutoIncrement() (isAutoIncrement bool, ok bool)
AutoIncrement returns the column is auto increment or not.
func (ColumnType) ColumnType ¶
func (ct ColumnType) ColumnType() (columnType string, ok bool)
ColumnType returns the database type of the column. like `varchar(16)`
func (ColumnType) Comment ¶
func (ct ColumnType) Comment() (value string, ok bool)
Comment returns the comment of current column.
func (ColumnType) DatabaseTypeName ¶
func (ct ColumnType) DatabaseTypeName() string
DatabaseTypeName returns the database system name of the column type. If an empty string is returned, then the driver type name is not supported. Consult your driver documentation for a list of driver data types. Length specifiers are not included. Common type names include "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL", "INT", and "BIGINT".
func (ColumnType) DecimalSize ¶
func (ct ColumnType) DecimalSize() (precision int64, scale int64, ok bool)
DecimalSize returns the scale and precision of a decimal type.
func (ColumnType) DefaultValue ¶
func (ct ColumnType) DefaultValue() (value string, ok bool)
DefaultValue returns the default value of current column.
func (ColumnType) Length ¶
func (ct ColumnType) Length() (length int64, ok bool)
Length returns the column type length for variable length column types
func (ColumnType) Name ¶
func (ct ColumnType) Name() string
Name returns the name or alias of the column.
func (ColumnType) Nullable ¶
func (ct ColumnType) Nullable() (nullable bool, ok bool)
Nullable reports whether the column may be null.
func (ColumnType) PrimaryKey ¶
func (ct ColumnType) PrimaryKey() (isPrimaryKey bool, ok bool)
PrimaryKey returns the column is primary key or not.
func (ColumnType) ScanType ¶
func (ct ColumnType) ScanType() reflect.Type
ScanType returns a Go type suitable for scanning into using Rows.Scan.
func (ColumnType) Unique ¶
func (ct ColumnType) Unique() (unique bool, ok bool)
Unique reports whether the column may be unique.
type GormDataTypeInterface ¶
GormDataTypeInterface gorm data type interface
type Index ¶
type Index struct { TableName string NameValue string ColumnList []string PrimaryKeyValue sql.NullBool UniqueValue sql.NullBool OptionValue string }
Index implements gorm.Index interface
func (Index) PrimaryKey ¶
PrimaryKey returns the index is primary key or not.
type Migrator ¶
type Migrator struct {
Config
}
Migrator m struct
func (Migrator) AlterColumn ¶
AlterColumn alter value's `field` column' type based on schema definition
func (Migrator) AutoMigrate ¶
AutoMigrate auto migrate values
func (Migrator) BuildIndexOptions ¶
func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{})
BuildIndexOptions build index options
func (Migrator) ColumnTypes ¶
func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)
ColumnTypes return columnTypes []gorm.ColumnType and execErr error
func (Migrator) CreateConstraint ¶
CreateConstraint create constraint
func (Migrator) CreateIndex ¶
CreateIndex create index `name`
func (Migrator) CreateTable ¶
CreateTable create table in database for values
func (Migrator) CreateView ¶
func (m Migrator) CreateView(name string, option gorm.ViewOption) error
CreateView create view from Query in gorm.ViewOption. Query in gorm.ViewOption is a subquery
// CREATE VIEW `user_view` AS SELECT * FROM `users` WHERE age > 20 q := DB.Model(&User{}).Where("age > ?", 20) DB.Debug().Migrator().CreateView("user_view", gorm.ViewOption{Query: q}) // CREATE OR REPLACE VIEW `users_view` AS SELECT * FROM `users` WITH CHECK OPTION q := DB.Model(&User{}) DB.Debug().Migrator().CreateView("user_view", gorm.ViewOption{Query: q, Replace: true, CheckOption: "WITH CHECK OPTION"})
func (Migrator) CurrentDatabase ¶
CurrentDatabase returns current database name
func (Migrator) CurrentTable ¶
CurrentTable returns current statement's table expression
func (Migrator) DataTypeOf ¶
DataTypeOf return field's db data type
func (Migrator) DropColumn ¶
DropColumn drop value's `name` column
func (Migrator) DropConstraint ¶
DropConstraint drop constraint
func (Migrator) FullDataTypeOf ¶
FullDataTypeOf returns field's db full data type
func (Migrator) GetIndexes ¶
GetIndexes return Indexes []gorm.Index and execErr error
func (Migrator) GetTypeAliases ¶
GetTypeAliases return database type aliases
func (Migrator) GuessConstraintAndTable ¶
func (m Migrator) GuessConstraintAndTable(stmt *gorm.Statement, name string) (_ *schema.Constraint, _ *schema.Check, table string)
GuessConstraintAndTable guess statement's constraint and it's table based on name
func (Migrator) HasConstraint ¶
HasConstraint check has constraint or not
func (Migrator) HasTable ¶
HasTable returns table exists or not for value, value could be a struct or string
func (Migrator) MigrateColumn ¶
func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnType gorm.ColumnType) error
MigrateColumn migrate column
func (Migrator) RenameColumn ¶
RenameColumn rename value's field name from oldName to newName
func (Migrator) RenameIndex ¶
RenameIndex rename index from oldName to newName
func (Migrator) RenameTable ¶
RenameTable rename table from oldName to newName
func (Migrator) ReorderModels ¶
ReorderModels reorder models according to constraint dependencies
func (Migrator) RunWithValue ¶
RunWithValue run migration with statement value
type TableType ¶
type TableType struct { SchemaValue string NameValue string TypeValue string CommentValue sql.NullString }
TableType table type implements TableType interface