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.2 KiB
Go

package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ UserPlatformModel = (*customUserPlatformModel)(nil)
type (
// UserPlatformModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserPlatformModel.
UserPlatformModel interface {
userPlatformModel
FindOneByPlatformAndPUid(ctx context.Context, platform string, pUid string) (*UserPlatform, error)
}
customUserPlatformModel struct {
*defaultUserPlatformModel
}
)
// NewUserPlatformModel returns a model for the database table.
func NewUserPlatformModel(conn sqlx.SqlConn) UserPlatformModel {
return &customUserPlatformModel{
defaultUserPlatformModel: newUserPlatformModel(conn),
}
}
func (c *customUserPlatformModel) FindOneByPlatformAndPUid(ctx context.Context, platform string, pUid string) (*UserPlatform, error) {
query := fmt.Sprintf("select %s from %s where `platform` = ? and `p_uid` = ? limit 1", userPlatformRows, c.table)
var resp UserPlatform
err := c.conn.QueryRowCtx(ctx, &resp, query, platform, pUid)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}