If migration is to be performed with dynmgrm, you must use the dynmgrm
tag.
package main
type User struct {
ProjectID string `gorm:"primaryKey dynmgrm:"pk"`
ID string `gorm:"primaryKey dynmgrm:"sk;gsi-pk:id_name-index"`
Name string `dynmgrm:"gsi-sk:id_name-index;lsi-sk:name-index"`
Note string `dynmgrm:"non-projective:[id_name-index,name-index]"`
}
Tag Name | Format | Description |
---|---|---|
pk | - | field will be the PK attribute of the table. |
sk | - | field will be the SK attribute of the table. |
gsi-pk | :<index name> | field will be the PK attribute of the specified Global Secondary Index. It works with Migrator.CreateIndex() |
gsi-sk | :<index name> | field will be the SK attribute of the specified Global Secondary Index. It works with Migrator.CreateIndex() |
lsi-sk | :<index name> | field will be the SK attribute of the specified Local Secondary Index. |
non-projective | :[(,)<index name>] | exclude from projection at enumerated Index. |
package main
import (
"github.com/miyamo2/dynmgrm"
"gorm.io/gorm"
)
type User struct {
ProjectID string `gorm:"primaryKey dynmgrm:"pk"`
ID string `gorm:"primaryKey dynmgrm:"sk;gsi-pk:id_name-index"`
Name string `dynmgrm:"gsi-sk:id_name-index;lsi-sk:name-index"`
Note string `dynmgrm:"non-projective:[id_name-index,name-index]"`
}
func main() {
db, err := gorm.Open(dynmgrm.New())
if err != nil {
panic(err)
}
db.Migrator().CreateTable(&User{})
}
package main
import (
"github.com/miyamo2/dynmgrm"
"gorm.io/gorm"
)
type User struct {
ProjectID string `gorm:"primaryKey dynmgrm:"pk"`
ID string `gorm:"primaryKey dynmgrm:"sk;gsi-pk:id_name-index"`
Name string `dynmgrm:"gsi-sk:id_name-index;lsi-sk:name-index"`
Note string `dynmgrm:"non-projective:[id_name-index,name-index]"`
}
func main() {
db, err := gorm.Open(dynmgrm.New())
if err != nil {
panic(err)
}
db.Migrator().CreateIndex(&User{}, "")
}