42 lines
1.1 KiB
Go
Executable File
42 lines
1.1 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ NhWalletModel = (*customNhWalletModel)(nil)
|
|
|
|
type (
|
|
// NhWalletModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customNhWalletModel.
|
|
NhWalletModel interface {
|
|
nhWalletModel
|
|
withSession(session sqlx.Session) NhWalletModel
|
|
FindWalletByAddress(ctx context.Context, address ...string) (uint, error)
|
|
}
|
|
|
|
customNhWalletModel struct {
|
|
*defaultNhWalletModel
|
|
}
|
|
)
|
|
|
|
func (m *customNhWalletModel) FindWalletByAddress(ctx context.Context, address ...string) (uint, error) {
|
|
query := fmt.Sprintf("select `uid` from %s where `address` in ? limit 1", m.table)
|
|
var uid uint
|
|
err := m.conn.QueryRowCtx(ctx, &uid, query, address)
|
|
return uid, err
|
|
}
|
|
|
|
// NewNhWalletModel returns a model for the database table.
|
|
func NewNhWalletModel(conn sqlx.SqlConn) NhWalletModel {
|
|
return &customNhWalletModel{
|
|
defaultNhWalletModel: newNhWalletModel(conn),
|
|
}
|
|
}
|
|
|
|
func (m *customNhWalletModel) withSession(session sqlx.Session) NhWalletModel {
|
|
return NewNhWalletModel(sqlx.NewSqlConnFromSession(session))
|
|
}
|