niki/repository/mysql/kind_box/exist_kindbox.go

35 lines
1.1 KiB
Go

package mysqlkindbox
import (
"context"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (d DB) BenefactorKindBoxExist(ctx context.Context, benefactorID, kindBoxID uint) (bool, error) {
const op = "mysqlkindbox.BenefactorKindBoxExist"
var count int
if err := d.conn.Conn().QueryRowContext(ctx, `SELECT COUNT(*) FROM kind_boxes WHERE benefactor_id = ? AND id = ?`, benefactorID, kindBoxID).Scan(&count); err != nil {
return false, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
}
return count > 0, nil
}
func (d DB) KindBoxExist(ctx context.Context, kindBoxID uint) (bool, error) {
const op = "mysqlkindbox.KindBoxExist"
var count int
if err := d.conn.Conn().QueryRowContext(ctx, `SELECT COUNT(*) FROM kind_boxes WHERE id = ?`, kindBoxID).Scan(&count); err != nil {
return false, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
}
return count > 0, nil
}