tribally report
This commit is contained in:
45
internal/model/nh_global_data_model.go
Executable file
45
internal/model/nh_global_data_model.go
Executable file
@@ -0,0 +1,45 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user