pg_partner_dao.go 1.0 KB
package dao

import (
	"fmt"
	"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
	"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
	. "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
)

type PartnerInfoDao struct {
	transactionContext *transaction.TransactionContext
}

func (dao *PartnerInfoDao) Update(queryOptions map[string]interface{}) error {
	tx := dao.transactionContext.PgTx
	m := new(models.PartnerInfo)
	query := NewQuery(tx.Model(m), queryOptions)
	query.SetUpdate(`account=?`, "Account")
	query.SetUpdate(`password=?`, "Password")
	query.SetWhere(`id=?`, "Id")
	if _, ok := queryOptions["Id"]; !ok {
		return fmt.Errorf(`error: miss param "Id"`)
	}
	_, err := query.Update()
	return err
}

func NewPartnerInfoDao(transactionContext *transaction.TransactionContext) (*PartnerInfoDao, error) {
	if transactionContext == nil {
		return nil, fmt.Errorf("transactionContext参数不能为nil")
	} else {
		return &PartnerInfoDao{
			transactionContext: transactionContext,
		}, nil
	}
}