index.go 1023 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package migrator
  2. import "database/sql"
  3. // Index implements gorm.Index interface
  4. type Index struct {
  5. TableName string
  6. NameValue string
  7. ColumnList []string
  8. PrimaryKeyValue sql.NullBool
  9. UniqueValue sql.NullBool
  10. OptionValue string
  11. }
  12. // Table return the table name of the index.
  13. func (idx Index) Table() string {
  14. return idx.TableName
  15. }
  16. // Name return the name of the index.
  17. func (idx Index) Name() string {
  18. return idx.NameValue
  19. }
  20. // Columns return the columns of the index
  21. func (idx Index) Columns() []string {
  22. return idx.ColumnList
  23. }
  24. // PrimaryKey returns the index is primary key or not.
  25. func (idx Index) PrimaryKey() (isPrimaryKey bool, ok bool) {
  26. return idx.PrimaryKeyValue.Bool, idx.PrimaryKeyValue.Valid
  27. }
  28. // Unique returns whether the index is unique or not.
  29. func (idx Index) Unique() (unique bool, ok bool) {
  30. return idx.UniqueValue.Bool, idx.UniqueValue.Valid
  31. }
  32. // Option return the optional attribute of the index
  33. func (idx Index) Option() string {
  34. return idx.OptionValue
  35. }