@@ -9,15 +9,6 @@ import (
99 "gorm.io/gorm"
1010)
1111
12- type SysDictionaryToPostgresql struct {
13- global.GVA_MODEL
14- Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"`
15- Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"`
16- Status * bool `json:"status" form:"status" gorm:"column:status;comment:状态"`
17- Description string `json:"description" form:"description" gorm:"column:description;comment:'描述'"`
18- SysDictionaryDetails []model.SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"`
19- }
20-
2112func InitSysDictionary (db * gorm.DB ) (err error ) {
2213 var status = new (bool )
2314 * status = true
@@ -34,32 +25,9 @@ func InitSysDictionary(db *gorm.DB) (err error) {
3425 color .Danger .Println ("sys_dictionaries表的初始数据已存在!" )
3526 return nil
3627 }
37- if tx .Create (& Dictionaries ).Error != nil { // 遇到错误时回滚事务
38- return err
39- }
40- return nil
41- })
42- }
43-
44- func InitSysDictionaryToPostgresql (db * gorm.DB ) (err error ) {
45- status := new (bool )
46- * status = true
47- Dictionaries := []SysDictionaryToPostgresql {
48- {GVA_MODEL : global.GVA_MODEL {ID : 1 , CreatedAt : time .Now (), UpdatedAt : time .Now ()}, Name : "性别" , Type : "sex" , Status : status , Description : "性别字典" },
49- {GVA_MODEL : global.GVA_MODEL {ID : 2 , CreatedAt : time .Now (), UpdatedAt : time .Now ()}, Name : "数据库int类型" , Type : "int" , Status : status , Description : "int类型对应的数据库类型" },
50- {GVA_MODEL : global.GVA_MODEL {ID : 3 , CreatedAt : time .Now (), UpdatedAt : time .Now ()}, Name : "数据库时间日期类型" , Type : "time.Time" , Status : status , Description : "数据库时间日期类型" },
51- {GVA_MODEL : global.GVA_MODEL {ID : 4 , CreatedAt : time .Now (), UpdatedAt : time .Now ()}, Name : "数据库浮点型" , Type : "float64" , Status : status , Description : "数据库浮点型" },
52- {GVA_MODEL : global.GVA_MODEL {ID : 5 , CreatedAt : time .Now (), UpdatedAt : time .Now ()}, Name : "数据库字符串" , Type : "string" , Status : status , Description : "数据库字符串" },
53- {GVA_MODEL : global.GVA_MODEL {ID : 6 , CreatedAt : time .Now (), UpdatedAt : time .Now ()}, Name : "数据库bool类型" , Type : "bool" , Status : status , Description : "数据库bool类型" },
54- }
55- return db .Transaction (func (tx * gorm.DB ) error {
56- if tx .Where ("id IN ?" , []int {1 , 6 }).Find (& []model.SysDictionary {}).RowsAffected == 2 {
57- color .Danger .Println ("sys_dictionaries表的初始数据已存在!" )
58- return nil
59- }
60- if tx .Create (& Dictionaries ).Error != nil { // 遇到错误时回滚事务
28+ if err := tx .Create (& Dictionaries ).Error ; err != nil { // 遇到错误时回滚事务
6129 return err
6230 }
6331 return nil
6432 })
65- }
33+ }
0 commit comments