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 } }