package gorm
import (
"reflect"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
)
func (db *DB ) Migrator () Migrator {
tx := db .getInstance ()
for len (tx .Statement .scopes ) > 0 {
tx = tx .executeScopes ()
}
return tx .Dialector .Migrator (tx .Session (&Session {}))
}
func (db *DB ) AutoMigrate (dst ...interface {}) error {
return db .Migrator ().AutoMigrate (dst ...)
}
type ViewOption struct {
Replace bool
CheckOption string
Query *DB
}
type ColumnType interface {
Name () string
DatabaseTypeName () string
ColumnType () (columnType string , ok bool )
PrimaryKey () (isPrimaryKey bool , ok bool )
AutoIncrement () (isAutoIncrement bool , ok bool )
Length () (length int64 , ok bool )
DecimalSize () (precision int64 , scale int64 , ok bool )
Nullable () (nullable bool , ok bool )
Unique () (unique bool , ok bool )
ScanType () reflect .Type
Comment () (value string , ok bool )
DefaultValue () (value string , ok bool )
}
type Index interface {
Table () string
Name () string
Columns () []string
PrimaryKey () (isPrimaryKey bool , ok bool )
Unique () (unique bool , ok bool )
Option () string
}
type TableType interface {
Schema () string
Name () string
Type () string
Comment () (comment string , ok bool )
}
type Migrator interface {
AutoMigrate (dst ...interface {}) error
CurrentDatabase () string
FullDataTypeOf (*schema .Field ) clause .Expr
GetTypeAliases (databaseTypeName string ) []string
CreateTable (dst ...interface {}) error
DropTable (dst ...interface {}) error
HasTable (dst interface {}) bool
RenameTable (oldName, newName interface {}) error
GetTables () (tableList []string , err error )
TableType (dst interface {}) (TableType , error )
AddColumn (dst interface {}, field string ) error
DropColumn (dst interface {}, field string ) error
AlterColumn (dst interface {}, field string ) error
MigrateColumn (dst interface {}, field *schema .Field , columnType ColumnType ) error
HasColumn (dst interface {}, field string ) bool
RenameColumn (dst interface {}, oldName, field string ) error
ColumnTypes (dst interface {}) ([]ColumnType , error )
CreateView (name string , option ViewOption ) error
DropView (name string ) error
CreateConstraint (dst interface {}, name string ) error
DropConstraint (dst interface {}, name string ) error
HasConstraint (dst interface {}, name string ) bool
CreateIndex (dst interface {}, name string ) error
DropIndex (dst interface {}, name string ) error
HasIndex (dst interface {}, name string ) bool
RenameIndex (dst interface {}, oldName, newName string ) error
GetIndexes (dst interface {}) ([]Index , error )
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .