44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package data
|
|
|
|
import (
|
|
"PaymentCenter/app/http/entities"
|
|
"PaymentCenter/app/models/appmodel"
|
|
"xorm.io/builder"
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
type AppRepo struct {
|
|
repo xorm.Interface
|
|
}
|
|
|
|
func NewAppRepo(repo xorm.Interface) *AppRepo {
|
|
return &AppRepo{
|
|
repo: repo,
|
|
}
|
|
}
|
|
|
|
func (m *AppRepo) AppList(conn builder.Cond, pageFilter entities.PageRequest, appList *[]appmodel.App) (int64, error) {
|
|
repo := m.repo.Where(conn)
|
|
if pageFilter.Page > 0 {
|
|
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
|
}
|
|
return repo.Desc("create_time").FindAndCount(appList)
|
|
}
|
|
|
|
func (m *AppRepo) AppInsertOne(app *appmodel.App) (int64, error) {
|
|
return m.repo.InsertOne(app)
|
|
}
|
|
|
|
func (m *AppRepo) AppDelete(app *appmodel.App, conn builder.Cond) (int64, error) {
|
|
return m.repo.Where(conn).Delete(app)
|
|
}
|
|
|
|
// columns 参数为要更新的字段
|
|
func (m *AppRepo) AppUpdate(app *appmodel.App, conn builder.Cond, columns ...string) (int64, error) {
|
|
return m.repo.Where(conn).MustCols(columns...).Update(app)
|
|
}
|
|
|
|
func (m *AppRepo) AppGet(app *appmodel.App, conn builder.Cond) (bool, error) {
|
|
return m.repo.Where(conn).Get(app)
|
|
}
|