2022-06-17 06:00:57 +03:00
|
|
|
package migrator
|
|
|
|
|
|
|
|
import "database/sql"
|
|
|
|
|
|
|
|
// Index implements gorm.Index interface
|
|
|
|
type Index struct {
|
|
|
|
TableName string
|
|
|
|
NameValue string
|
|
|
|
ColumnList []string
|
|
|
|
PrimaryKeyValue sql.NullBool
|
|
|
|
UniqueValue sql.NullBool
|
|
|
|
OptionValue string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Table return the table name of the index.
|
|
|
|
func (idx Index) Table() string {
|
|
|
|
return idx.TableName
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:32:46 +03:00
|
|
|
// Name return the name of the index.
|
2022-06-17 06:00:57 +03:00
|
|
|
func (idx Index) Name() string {
|
|
|
|
return idx.NameValue
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:32:46 +03:00
|
|
|
// Columns return the columns of the index
|
2022-06-17 06:00:57 +03:00
|
|
|
func (idx Index) Columns() []string {
|
|
|
|
return idx.ColumnList
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrimaryKey returns the index is primary key or not.
|
|
|
|
func (idx Index) PrimaryKey() (isPrimaryKey bool, ok bool) {
|
|
|
|
return idx.PrimaryKeyValue.Bool, idx.PrimaryKeyValue.Valid
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unique returns whether the index is unique or not.
|
|
|
|
func (idx Index) Unique() (unique bool, ok bool) {
|
|
|
|
return idx.UniqueValue.Bool, idx.UniqueValue.Valid
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:32:46 +03:00
|
|
|
// Option return the optional attribute of the index
|
2022-06-17 06:00:57 +03:00
|
|
|
func (idx Index) Option() string {
|
|
|
|
return idx.OptionValue
|
|
|
|
}
|