master
Evan Chen 2022-01-09 05:04:24 +08:00
parent 9136b5ce70
commit 810a59b3fe
2 changed files with 7 additions and 5 deletions

View File

@ -12,6 +12,7 @@ type Attribute struct {
ID uint `gorm:"primaryKey"`
Key string `gorm:"unique;not null"`
Name string
Description string
Value string
Default string
@ -33,7 +34,7 @@ func Init() {
}
}
func Add(Key, Description, Default string) error {
func Add(Key, Name, Description, Default string) error {
ctr := 0
store.DB.Raw(`select count(*) from "attributes" where "key" = ?`, Key).
Scan(&ctr)
@ -42,6 +43,7 @@ func Add(Key, Description, Default string) error {
}
a := &Attribute{
Key: Key,
Name: Name,
Description: Description,
Default: Default,
Value: Default,

View File

@ -13,10 +13,10 @@ func TestAttr(t *testing.T) {
viper.Set("db.type", "sqlite")
store.Setup()
Init()
fmt.Println(Add("test", "", "1"))
fmt.Println(Add("test1", "", "2"))
fmt.Println(Add("test2", "", "2"))
fmt.Println(Add("test3", "", "2"))
fmt.Println(Add("test", "test", "", "1"))
fmt.Println(Add("test1", "test1", "", "2"))
fmt.Println(Add("test1", "test2", "", "2"))
fmt.Println(Add("test1", "test3", "", "2"))
fmt.Println(Set("test", "reset"))
fmt.Println(Get("test"))
}