This commit is contained in:
2024-12-18 03:08:49 +08:00
parent c2d44e5947
commit 2378d75406
5 changed files with 93 additions and 28 deletions

View File

@ -12,39 +12,21 @@ func NewFacade(tableName string, dbFunc func() *gorm.DB) *Facade {
}
func (t *Facade) NewQuery() *Query {
if t.dbFunc != nil {
return NewQuery(t.tableName).SetDB(t.dbFunc())
}
return NewQuery(t.tableName)
return NewQuery(t.tableName, t.dbFunc())
}
func (t *Facade) NewUpdate() *Update {
if t.dbFunc != nil {
return NewUpdate(t.tableName).SetDB(t.dbFunc())
}
return NewUpdate(t.tableName)
return NewUpdate(t.tableName, t.dbFunc())
}
func (t *Facade) NewInsert() *Insert {
if t.dbFunc != nil {
return NewInsert(t.tableName).SetDB(t.dbFunc())
}
return NewInsert(t.tableName)
return NewInsert(t.tableName, t.dbFunc())
}
func (t *Facade) NewDelete() *Delete {
if t.dbFunc != nil {
return NewDelete(t.tableName).SetDB(t.dbFunc())
}
return NewDelete(t.tableName)
return NewDelete(t.tableName, t.dbFunc())
}
func (t *Facade) Create(val interface{}) error {
if t.dbFunc != nil {
db := t.dbFunc()
if db != nil {
return Create(val, db)
}
}
return Create(val)
return Create(val, t.dbFunc())
}