我喜欢做的事情是,将gorm功能包装在没有特定结构参数的某些功能后面。
func (e *Engine) Create(object interface{}) error {
tx := e.db.Begin()
if err := tx.Create(&object).Error; err != nil {
tx.Rollback()
return err
}
tx.Commit()
return nil
}
存在使用
db.CreateTable(&<specific struct{})
创建的特定表。但是它失败并显示以下错误:
Can't create <specific struct>: no such table:
这是与gorm / golang结合使用的一种方法,以及如何包装?
最佳答案
请参阅Adrian的评论。非常感谢,睁开我疲倦的眼睛。
传递object
而不是&object
关于go - golang gorm包装功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48191229/