feat: add method GetIndexes (#5436)
* feat: add method GetIndexes * feat: add default impl for Index interface * feat: fmt
This commit is contained in:
		
							parent
							
								
									8d45714628
								
							
						
					
					
						commit
						1305f637f8
					
				
							
								
								
									
										10
									
								
								migrator.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								migrator.go
									
									
									
									
									
								
							| @ -51,6 +51,15 @@ type ColumnType interface { | ||||
| 	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 | ||||
| } | ||||
| 
 | ||||
| // Migrator migrator interface
 | ||||
| type Migrator interface { | ||||
| 	// AutoMigrate
 | ||||
| @ -90,4 +99,5 @@ type Migrator interface { | ||||
| 	DropIndex(dst interface{}, name string) error | ||||
| 	HasIndex(dst interface{}, name string) bool | ||||
| 	RenameIndex(dst interface{}, oldName, newName string) error | ||||
| 	GetIndexes(dst interface{}) ([]Index, error) | ||||
| } | ||||
|  | ||||
							
								
								
									
										43
									
								
								migrator/index.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								migrator/index.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| 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 | ||||
| } | ||||
| 
 | ||||
| // Name return the name  of the index.
 | ||||
| func (idx Index) Name() string { | ||||
| 	return idx.NameValue | ||||
| } | ||||
| 
 | ||||
| // Columns return the columns fo the index
 | ||||
| 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 | ||||
| } | ||||
| 
 | ||||
| // Option return the optional attribute fo the index
 | ||||
| func (idx Index) Option() string { | ||||
| 	return idx.OptionValue | ||||
| } | ||||
| @ -3,6 +3,7 @@ package migrator | ||||
| import ( | ||||
| 	"context" | ||||
| 	"database/sql" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"reflect" | ||||
| 	"regexp" | ||||
| @ -854,3 +855,8 @@ func (m Migrator) CurrentTable(stmt *gorm.Statement) interface{} { | ||||
| 	} | ||||
| 	return clause.Table{Name: stmt.Table} | ||||
| } | ||||
| 
 | ||||
| // GetIndexes return Indexes []gorm.Index and execErr error
 | ||||
| func (m Migrator) GetIndexes(dst interface{}) ([]gorm.Index, error) { | ||||
| 	return nil, errors.New("not support") | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 qqxhb
						qqxhb