You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ GiftModel = (*customGiftModel)(nil)
|
|
|
|
type (
|
|
// GiftModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customGiftModel.
|
|
GiftModel interface {
|
|
giftModel
|
|
FindOneByGiftId(ctx context.Context, giftId string) (*Gift, error)
|
|
}
|
|
|
|
customGiftModel struct {
|
|
*defaultGiftModel
|
|
}
|
|
)
|
|
|
|
// NewGiftModel returns a model for the database table.
|
|
func NewGiftModel(conn sqlx.SqlConn) GiftModel {
|
|
return &customGiftModel{
|
|
defaultGiftModel: newGiftModel(conn),
|
|
}
|
|
}
|
|
|
|
func (m *customGiftModel) FindOneByGiftId(ctx context.Context, giftId string) (*Gift, error) {
|
|
query := fmt.Sprintf("select %s from %s where `gift_id` = ? limit 1", giftRows, m.table)
|
|
var resp Gift
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, giftId)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlc.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|