46 lines
1.2 KiB
Go
Executable File
46 lines
1.2 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ NhGlobalDataModel = (*customNhGlobalDataModel)(nil)
|
|
|
|
type (
|
|
// NhGlobalDataModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customNhGlobalDataModel.
|
|
NhGlobalDataModel interface {
|
|
nhGlobalDataModel
|
|
withSession(session sqlx.Session) NhGlobalDataModel
|
|
GetValue(ctx context.Context, key string) (string, error)
|
|
}
|
|
|
|
customNhGlobalDataModel struct {
|
|
*defaultNhGlobalDataModel
|
|
}
|
|
)
|
|
|
|
func (m *customNhGlobalDataModel) GetValue(ctx context.Context, key string) (string, error) {
|
|
result, err := m.FindOneByKey(ctx, key)
|
|
if err != nil {
|
|
if errors.Is(err, ErrNotFound) {
|
|
return "", nil
|
|
}
|
|
return "", err
|
|
}
|
|
return result.Value, nil
|
|
}
|
|
|
|
// NewNhGlobalDataModel returns a model for the database table.
|
|
func NewNhGlobalDataModel(conn sqlx.SqlConn) NhGlobalDataModel {
|
|
return &customNhGlobalDataModel{
|
|
defaultNhGlobalDataModel: newNhGlobalDataModel(conn),
|
|
}
|
|
}
|
|
|
|
func (m *customNhGlobalDataModel) withSession(session sqlx.Session) NhGlobalDataModel {
|
|
return NewNhGlobalDataModel(sqlx.NewSqlConnFromSession(session))
|
|
}
|