From d8f1a70c4363071af5e8f3f941ef2ac84b7730a3 Mon Sep 17 00:00:00 2001 From: qqxhb <1252905006@qq.com> Date: Thu, 16 Jun 2022 20:27:56 +0800 Subject: [PATCH] feat: add default impl for Index interface --- migrator/index.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 migrator/index.go diff --git a/migrator/index.go b/migrator/index.go new file mode 100644 index 00000000..6f55be93 --- /dev/null +++ b/migrator/index.go @@ -0,0 +1,44 @@ +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 returns the table name of the index. +func (idx Index) Table() string { + return idx.TableName +} + +// Name returns 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 reports 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 +}