|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "xorm.io/xorm"
- )
-
- type NursingHomePackageWithDayDb struct {
- Db *xorm.Engine `json:"db"`
- PackageId int `json:"package_id"`
- }
-
- func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) Set(packageId int) { // set方法
- nursingHomePackageWithDayDb.Db = Db
- nursingHomePackageWithDayDb.PackageId = packageId
- }
-
- func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) GetNursingHomePackageWithDay(id int) (m *model.NursingHomePackageWithDay, err error) {
- m = new(model.NursingHomePackageWithDay)
- has, err := nursingHomePackageWithDayDb.Db.Where("id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) FindNursingHomePackageWithDay() (*[]model.NursingHomePackageWithDay, error) {
- var m []model.NursingHomePackageWithDay
- if err := nursingHomePackageWithDayDb.Db.Where("package_id =?", nursingHomePackageWithDayDb.PackageId).Asc("id").Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) NursingHomePackageWithDayInsert(m *model.NursingHomePackageWithDay) (int, error) {
- _, err := nursingHomePackageWithDayDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) BatchAddNursingHomePackageWithDaysBySession(session *xorm.Session, mm []*model.NursingHomePackageWithDay) (int64, error) {
- affected, err := session.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) BatchAddNursingHomePackageWithDays(mm []*model.NursingHomePackageWithDay) (int64, error) {
- affected, err := nursingHomePackageWithDayDb.Db.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) NursingHomePackageWithDayDeleteBySession(session *xorm.Session) (int64, error) {
- return Db.Where("package_id = ?", nursingHomePackageWithDayDb.PackageId).Delete(model.NursingHomePackageWithDay{})
- }
-
- func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) NursingHomePackageWithDayUpdate(Db *xorm.Engine, id interface{}, m *model.NursingHomePackageWithDay, forceColums ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColums != nil {
- affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(m)
- } else {
- affected, err = Db.Where("id=?", id).Update(m)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
|