2024-05-31 12:36:48 +00:00
|
|
|
package mysqlrefertime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-31 12:36:48 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
|
|
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
2024-07-30 11:05:41 +00:00
|
|
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
2024-05-31 12:36:48 +00:00
|
|
|
)
|
|
|
|
|
2024-07-30 11:05:41 +00:00
|
|
|
func (d *DB) Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error) {
|
2024-05-31 12:36:48 +00:00
|
|
|
const op = richerror.Op("mysqlrefertime.Get")
|
|
|
|
|
2024-07-30 11:05:41 +00:00
|
|
|
query := `select * from refer_times where id = ?`
|
|
|
|
//nolint
|
|
|
|
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyReferTimeGetByID, query)
|
|
|
|
if err != nil {
|
|
|
|
return entity.ReferTime{}, richerror.New(op).WithErr(err).
|
|
|
|
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
|
|
|
|
|
|
|
row := stmt.QueryRowContext(ctx, referTimeID)
|
2024-05-31 12:36:48 +00:00
|
|
|
r, err := scanReferTime(row)
|
|
|
|
if err != nil {
|
|
|
|
return entity.ReferTime{}, richerror.New(op).WithErr(err).
|
|
|
|
WithMessage(errmsg.ErrorMsgCantScanQueryResult).WithKind(richerror.KindUnexpected)
|
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-05-31 12:36:48 +00:00
|
|
|
return r, nil
|
|
|
|
}
|