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

View File

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