diff --git a/migrator.go b/migrator.go index b566c10e..31183ad5 100644 --- a/migrator.go +++ b/migrator.go @@ -1,10 +1,9 @@ package gorm import ( - "reflect" - "gorm.io/gorm/clause" "gorm.io/gorm/schema" + "reflect" ) // Migrator returns migrator @@ -60,6 +59,16 @@ type Index interface { Option() string } +// TableType table type interface +type TableType interface { + Catalog() string + Schema() string + Name() string + Type() string + Engine() (engine string, ok bool) + Comment() (comment string, ok bool) +} + // Migrator migrator interface type Migrator interface { // AutoMigrate @@ -76,7 +85,7 @@ type Migrator interface { HasTable(dst interface{}) bool RenameTable(oldName, newName interface{}) error GetTables() (tableList []string, err error) - GetTableComment(tableName string) (comment string, err error) + TableType(dst interface{}) (TableType, error) // Columns AddColumn(dst interface{}, field string) error diff --git a/migrator/migrator.go b/migrator/migrator.go index bbc0dea1..410eff5e 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -948,7 +948,7 @@ func (m Migrator) GetTypeAliases(databaseTypeName string) []string { return nil } -// GetTableComment return table comment -func (m Migrator) GetTableComment(tableName string) (string, error) { - return "", errors.New("not support") +// TableType return tableType gorm.TableType and execErr error +func (m Migrator) TableType(dst interface{}) (gorm.TableType, error) { + return nil, errors.New("not support") } diff --git a/migrator/table_type.go b/migrator/table_type.go new file mode 100644 index 00000000..84fa3bca --- /dev/null +++ b/migrator/table_type.go @@ -0,0 +1,45 @@ +package migrator + +import ( + "database/sql" +) + +// TableType table type implements TableType interface +type TableType struct { + CatalogValue string + SchemaValue string + NameValue string + TypeValue string + EngineValue sql.NullString + CommentValue sql.NullString +} + +// Catalog returns the catalog of the table. +func (ct TableType) Catalog() string { + return ct.CatalogValue +} + +// Schema returns the schema of the table. +func (ct TableType) Schema() string { + return ct.SchemaValue +} + +// Name returns the name of the table. +func (ct TableType) Name() string { + return ct.NameValue +} + +// Type returns the type of the table. +func (ct TableType) Type() string { + return ct.TypeValue +} + +// Engine returns the engine of current table. +func (ct TableType) Engine() (engine string, ok bool) { + return ct.EngineValue.String, ct.EngineValue.Valid +} + +// Comment returns the comment of current table. +func (ct TableType) Comment() (comment string, ok bool) { + return ct.CommentValue.String, ct.CommentValue.Valid +}