You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
656 B

package db
import (
"database/sql"
"gorm.io/gorm"
)
type BaseModel struct {
db *gorm.DB
}
func (b *BaseModel) GetDb() *gorm.DB {
if b.db == nil {
b.db = Db
}
return b.db
}
func (b *BaseModel) SetDb(db *gorm.DB) {
b.db = db
}
func (b *BaseModel) Begin(opts ...*sql.TxOptions) *gorm.DB {
b.db = b.GetDb().Begin(opts...)
return b.db
}
func (b *BaseModel) Rollback() *gorm.DB {
b.db = b.GetDb().Rollback()
return b.db
}
func (b *BaseModel) Commit() *gorm.DB {
b.db = b.GetDb().Commit()
return b.db
}
func (b *BaseModel) Transaction(fc func(tx *gorm.DB) error, opts ...*sql.TxOptions) error {
return b.GetDb().Transaction(fc, opts...)
}