pg_notification_dao.go
879 字节
package dao
import (
"fmt"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"time"
)
type NotificationDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (dao *NotificationDao) ReadAllUnReadSentNotification(receiverId int64) (int, error) {
tx := dao.transactionContext.PgTx
result, err := tx.Query(
pg.Scan(),
`UPDATE sent_notifications SET is_read=?, read_time=? WHERE receiver @> '{"uid":?}'`,
true, time.Now(), receiverId)
if err != nil {
return 0, err
} else {
return result.RowsAffected(), nil
}
}
func NewNotificationDao(transactionContext *pgTransaction.TransactionContext) (*NotificationDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &NotificationDao{
transactionContext: transactionContext,
}, nil
}
}