Documentation ¶
Overview ¶
Package juice provides a set of utilities for mapping database query results to Go data structures.
Index ¶
- Variables
- func Bind[T any](rows *sql.Rows) (result T, err error)
- func BindWithResultMap[T any](rows *sql.Rows, resultMap ResultMap) (result T, err error)
- func ContextWithManager(ctx context.Context, manager Manager) context.Context
- func CtxWithParam(ctx context.Context, param Param) context.Context
- func HasTxManager(ctx context.Context) bool
- func IsTxManager(manager Manager) bool
- func MustRegisterEvalFunc(name string, v any)
- func RegisterEnvValueProvider(name string, provider EnvValueProvider)
- func RegisterEvalFunc(name string, v any) error
- func SessionWithContext(ctx context.Context, sess Session) context.Context
- type Action
- type AdapterExecutorFunc
- type BinderRouter
- type CacheMiddleware
- type ChooseNode
- type ColumnDestination
- type ConditionNode
- type Configuration
- type ConfigurationParser
- type DebugMiddleware
- type Engine
- func (e *Engine) CacheTx() TxCacheManager
- func (e *Engine) Close() error
- func (e *Engine) ContextCacheTx(ctx context.Context, opt *sql.TxOptions) TxCacheManager
- func (e *Engine) ContextTx(ctx context.Context, opt *sql.TxOptions) TxManager
- func (e *Engine) DB() *sql.DB
- func (e *Engine) Driver() driver.Driver
- func (e *Engine) GetConfiguration() *Configuration
- func (e *Engine) Object(v any) Executor
- func (e *Engine) SetConfiguration(cfg *Configuration)
- func (e *Engine) SetLocker(locker RWLocker)
- func (e *Engine) Tx() TxManager
- func (e *Engine) Use(middleware Middleware)
- type EnvValueProvider
- type EnvValueProviderFunc
- type Environment
- type Environments
- type EvalValue
- type ExecHandler
- type Executor
- type ExecutorAdapter
- type ExecutorAdapterGroup
- type ExprCompiler
- type ExprPretreatment
- type ExprPretreatmentChain
- type Expression
- type ForeachNode
- type GenericExecutor
- type GenericManager
- type GenericMiddleware
- type GenericMiddlewareGroup
- type GenericQueryHandler
- type H
- type IfNode
- type IncludeNode
- type Manager
- type Mapper
- func (m *Mapper) Attribute(key string) string
- func (m *Mapper) Configuration() *Configuration
- func (m *Mapper) Engine() *Engine
- func (m *Mapper) GetResultMapByID(id string) (ResultMap, error)
- func (m *Mapper) GetSQLNodeByID(id string) (Node, error)
- func (m *Mapper) Mappers() *Mappers
- func (m *Mapper) Namespace() string
- func (m *Mapper) Prefix() string
- type Mappers
- func (m *Mappers) Attribute(key string) string
- func (m *Mappers) Configuration() *Configuration
- func (m *Mappers) GetMapperByNamespace(namespace string) (*Mapper, bool)
- func (m *Mappers) GetStatement(v any) (*Statement, error)
- func (m *Mappers) GetStatementByID(id string) (*Statement, error)
- func (m *Mappers) Prefix() string
- type Middleware
- type MiddlewareGroup
- type Node
- type NodeGroup
- type OsEnvValueProvider
- type OtherwiseNode
- type Param
- type ParamCtxInjectorExecutor
- type ParamGroup
- type Parameter
- type QueryHandler
- type RWLocker
- type ResultBinder
- type ResultBinderGroup
- type ResultMap
- type RowResultMap
- type RowsResultMap
- type RowsScanner
- type SQLNode
- type SelectFieldAliasNode
- type Session
- type SessionCtxInjectorExecutor
- type SetNode
- type Setting
- type Settings
- type Statement
- func (s *Statement) Accept(translator driver.Translator, p Parameter) (query string, args []any, err error)
- func (s *Statement) Action() Action
- func (s *Statement) Attribute(key string) string
- func (s *Statement) Build(param Param) (query string, args []any, err error)
- func (s *Statement) Configuration() *Configuration
- func (s *Statement) Engine() *Engine
- func (s *Statement) ExecHandler() ExecHandler
- func (s *Statement) ForRead() bool
- func (s *Statement) ForWrite() bool
- func (s *Statement) ID() string
- func (s *Statement) IsInsert() bool
- func (s *Statement) Mapper() *Mapper
- func (s *Statement) Name() string
- func (s *Statement) Namespace() string
- func (s *Statement) QueryHandler() QueryHandler
- func (s *Statement) ResultMap() (ResultMap, error)
- type StringValue
- type SyntaxError
- type TextNode
- type TimeoutMiddleware
- type TrimNode
- type TxCacheManager
- type TxManager
- type ValuesNode
- type WhenNode
- type WhereNode
- type XMLParser
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyQuery is an error that is returned when the query is empty. ErrEmptyQuery = errors.New("empty query") // ErrResultMapNotSet is an error that is returned when the result map is not set. ErrResultMapNotSet = errors.New("resultMap not set") // ErrSqlNodeNotFound is an error that is returned when the sql node is not found. // nolint:unused ErrSqlNodeNotFound = errors.New("sql node not found") // ErrNilDestination is an error that is returned when the destination is nil. ErrNilDestination = errors.New("destination can not be nil") // ErrNilRows is an error that is returned when the rows is nil. ErrNilRows = errors.New("rows can not be nil") // ErrPointerRequired is an error that is returned when the destination is not a pointer. ErrPointerRequired = errors.New("destination must be a pointer") )
var CacheKeyFunc cacheKeyFunc = func(stmt *Statement, query string, args []any) (string, error) { writer := md5.New() writer.Write([]byte(stmt.ID() + query)) if len(args) > 0 { item, err := json.Marshal(args) if err != nil { return "", err } writer.Write(item) } return hex.EncodeToString(writer.Sum(nil)), nil }
CacheKeyFunc is the function which is used to generate the scopeCache key. default is the md5 of the query and args. reset the CacheKeyFunc variable to change the default behavior.
var ErrNoSession = errors.New("no session found in context")
ErrNoSession is the error that no session found in context.
var ErrTooManyRows = errors.New("juice: too many rows in result set")
ErrTooManyRows is returned when the result set has too many rows but excepted only one row.
Functions ¶
func BindWithResultMap ¶
BindWithResultMap bind sql.Rows to given entity with given ResultMap bind cover sql.Rows to given entity dest can be a pointer to a struct, a pointer to a slice of struct, or a pointer to a slice of any type. rows won't be closed when the function returns.
func ContextWithManager ¶
ContextWithManager returns a new context with the given Manager.
func CtxWithParam ¶ added in v1.3.6
CtxWithParam returns a new context with the parameter.
func HasTxManager ¶ added in v1.3.5
HasTxManager returns true if the context has a TxManager.
func IsTxManager ¶ added in v1.3.5
IsTxManager returns true if the manager is a TxManager.
func MustRegisterEvalFunc ¶
MustRegisterEvalFunc registers a function for eval. If an error occurs, it will panic.
func RegisterEnvValueProvider ¶
func RegisterEnvValueProvider(name string, provider EnvValueProvider)
RegisterEnvValueProvider registers an environment value provider. The key is a name of the provider. The value is a provider. It allows to override the default provider.
func RegisterEvalFunc ¶
RegisterEvalFunc registers a function for eval. The function must be a function with one return value. And Allowed to overwrite the built-in function.
Types ¶
type AdapterExecutorFunc ¶ added in v1.4.9
AdapterExecutorFunc is a function type that implements the ExecutorAdapter interface.
func (AdapterExecutorFunc) AdapterExecutor ¶ added in v1.4.9
func (f AdapterExecutorFunc) AdapterExecutor(e Executor) Executor
AdapterExecutor implements the ExecutorAdapter interface.
type BinderRouter ¶ added in v1.4.12
BinderRouter is a map that associates a string key to any value.
type CacheMiddleware ¶ added in v1.3.6
type CacheMiddleware[T any] struct { // contains filtered or unexported fields }
CacheMiddleware is a middleware that caches the result of the sql query.
func (*CacheMiddleware[T]) ExecContext ¶ added in v1.3.6
func (c *CacheMiddleware[T]) ExecContext(stmt *Statement, next ExecHandler) ExecHandler
ExecContext implements Middleware.
func (*CacheMiddleware[T]) QueryContext ¶ added in v1.3.6
func (c *CacheMiddleware[T]) QueryContext(stmt *Statement, next GenericQueryHandler[T]) GenericQueryHandler[T]
QueryContext implements Middleware.
type ChooseNode ¶
ChooseNode is a node of choose. ChooseNode can have multiple when nodes and one otherwise node. WhenNode is executed when test is true. OtherwiseNode is executed when all when nodes are false.
func (ChooseNode) Accept ¶
func (c ChooseNode) Accept(translator driver.Translator, p Parameter) (query string, args []any, err error)
Accept accepts parameters and returns query and arguments.
type ColumnDestination ¶ added in v1.1.3
type ColumnDestination interface { // Destination returns the destination for the given reflect value and column. Destination(rv reflect.Value, column []string) ([]any, error) }
ColumnDestination is a column destination which can be used to scan a row.
type ConditionNode ¶
type ConditionNode struct { Nodes NodeGroup // contains filtered or unexported fields }
func (*ConditionNode) Accept ¶
func (c *ConditionNode) Accept(translator driver.Translator, p Parameter) (query string, args []any, err error)
Accept accepts parameters and returns query and arguments. Accept implements Node interface.
func (*ConditionNode) Match ¶
func (c *ConditionNode) Match(p Parameter) (bool, error)
Match returns true if test is matched.
func (*ConditionNode) Parse ¶
func (c *ConditionNode) Parse(test string) (err error)
Parse with given expression.
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration is a configuration of juice.
func NewXMLConfiguration ¶
func NewXMLConfiguration(filename string) (*Configuration, error)
func NewXMLConfigurationWithFS ¶
func NewXMLConfigurationWithFS(fs fs.FS, filename string) (*Configuration, error)
NewXMLConfigurationWithFS creates a new Configuration from an XML file.
func (Configuration) Environments ¶
func (c Configuration) Environments() Environments
Environments returns the environments.
func (Configuration) Mappers ¶
func (c Configuration) Mappers() *Mappers
Mappers returns the mappers.
func (Configuration) Settings ¶
func (c Configuration) Settings() Settings
Settings returns the settings.
type ConfigurationParser ¶
type ConfigurationParser interface { // Parse parses the configuration from the reader. Parse(reader io.Reader) (*Configuration, error) }
ConfigurationParser is the interface for parsing configuration.
type DebugMiddleware ¶
type DebugMiddleware struct{}
DebugMiddleware is a middleware that prints the sql statement and the execution time.
func (*DebugMiddleware) ExecContext ¶
func (m *DebugMiddleware) ExecContext(stmt *Statement, next ExecHandler) ExecHandler
ExecContext implements Middleware. ExecContext will print the sql statement and the execution time.
func (*DebugMiddleware) QueryContext ¶
func (m *DebugMiddleware) QueryContext(stmt *Statement, next QueryHandler) QueryHandler
QueryContext implements Middleware. QueryContext will print the sql statement and the execution time.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the implementation of Manager interface and the core of juice.
func DefaultEngine ¶
func DefaultEngine(configuration *Configuration) (*Engine, error)
DefaultEngine is the default engine It adds an interceptor to log the statements
func NewEngine ¶
func NewEngine(configuration *Configuration) (*Engine, error)
NewEngine creates a new Engine
func (*Engine) CacheTx ¶ added in v1.3.2
func (e *Engine) CacheTx() TxCacheManager
CacheTx returns a TxCacheManager.
func (*Engine) ContextCacheTx ¶ added in v1.3.2
ContextCacheTx returns a TxCacheManager with the given context.
func (*Engine) GetConfiguration ¶
func (e *Engine) GetConfiguration() *Configuration
GetConfiguration returns the configuration of the engine
func (*Engine) SetConfiguration ¶
func (e *Engine) SetConfiguration(cfg *Configuration)
SetConfiguration sets the configuration of the engine
func (*Engine) SetLocker ¶ added in v1.3.3
SetLocker sets the locker of the engine it is not goroutine safe, so it should be called before the engine is used
func (*Engine) Use ¶
func (e *Engine) Use(middleware Middleware)
Use adds a middleware to the engine
type EnvValueProvider ¶
EnvValueProvider defines a environment value provider.
func GetEnvValueProvider ¶
func GetEnvValueProvider(key string) EnvValueProvider
GetEnvValueProvider returns a environment value provider.
type EnvValueProviderFunc ¶
EnvValueProviderFunc is a function type of environment value provider.
type Environment ¶
type Environment struct { // DataSource is a string in a driver-specific format. DataSource string // Driver is a driver for Driver string // MaxIdleConnNum is a maximum number of idle connections. MaxIdleConnNum int // MaxOpenConnNum is a maximum number of open connections. MaxOpenConnNum int // MaxConnLifetime is a maximum lifetime of a connection. MaxConnLifetime int // MaxIdleConnLifetime is a maximum lifetime of an idle connection. MaxIdleConnLifetime int // contains filtered or unexported fields }
Environment defines a environment. It contains a database connection configuration.
func (*Environment) Attr ¶
func (e *Environment) Attr(key string) string
Attr returns a value of the attribute.
func (*Environment) ID ¶
func (e *Environment) ID() string
ID returns a identifier of the environment.
type Environments ¶
type Environments struct {
// contains filtered or unexported fields
}
Environments is a collection of environments.
func (*Environments) Attr ¶ added in v1.3.7
func (e *Environments) Attr(key string) string
Attr returns a value of the attribute.
func (*Environments) DefaultEnv ¶
func (e *Environments) DefaultEnv() (*Environment, error)
DefaultEnv returns the default environment.
func (*Environments) Use ¶
func (e *Environments) Use(id string) (*Environment, error)
Use returns the environment specified by the identifier.
type ExecHandler ¶
ExecHandler defines the handler of the exec.
type Executor ¶
type Executor interface { // QueryContext executes a query that returns rows, typically a SELECT. // The param are the placeholder collection for this query. QueryContext(ctx context.Context, param Param) (*sql.Rows, error) // ExecContext executes a query without returning any rows. // The param are the placeholder collection for this query. ExecContext(ctx context.Context, param Param) (sql.Result, error) // Statement returns the statement of the current executor. Statement() *Statement // Session returns the session of the current executor. Session() Session }
Executor is an executor of SQL.
type ExecutorAdapter ¶ added in v1.4.9
type ExecutorAdapter interface { // AdapterExecutor injects the executor and returns the new executor. AdapterExecutor(Executor) Executor }
ExecutorAdapter is an interface for injecting the executor.
func NewParamCtxExecutorAdapter ¶ added in v1.4.9
func NewParamCtxExecutorAdapter() ExecutorAdapter
NewParamCtxExecutorAdapter returns a new ParamCtxInjectorExecutor.
func NewSessionCtxInjectorExecutorAdapter ¶ added in v1.4.9
func NewSessionCtxInjectorExecutorAdapter() ExecutorAdapter
NewSessionCtxInjectorExecutorAdapter returns a new SessionCtxInjectorExecutor.
type ExecutorAdapterGroup ¶ added in v1.4.9
type ExecutorAdapterGroup []ExecutorAdapter
ExecutorAdapterGroup is a group of executor injectors. It implements the ExecutorAdapter interface.
func (ExecutorAdapterGroup) AdapterExecutor ¶ added in v1.4.9
func (eg ExecutorAdapterGroup) AdapterExecutor(e Executor) Executor
AdapterExecutor implements the ExecutorAdapter interface. It wrapped the executor by the order of the group.
type ExprCompiler ¶ added in v1.4.9
type ExprCompiler interface { // Compile compiles the expression and returns the expression. Compile(expr string) (Expression, error) }
ExprCompiler is an evaluator of the expression.
var ( // DefaultExprCompiler is the default evaluator. // Reset it to change the default behavior. DefaultExprCompiler ExprCompiler = &goExprCompiler{pretreatment: exprPretreatmentChain} )
type ExprPretreatment ¶ added in v1.4.2
ExprPretreatment is an expression pretreatment. It is used to pretreatment the expression before parsing.
type ExprPretreatmentChain ¶ added in v1.4.2
type ExprPretreatmentChain []ExprPretreatment
ExprPretreatmentChain is an expression pretreatment chain.
func (ExprPretreatmentChain) PretreatmentExpr ¶ added in v1.4.2
func (e ExprPretreatmentChain) PretreatmentExpr(expr string) (string, error)
PretreatmentExpr implements the ExprPretreatment interface.
type Expression ¶ added in v1.3.8
type Expression interface { // Execute evaluates the expression and returns the value. Execute(params Parameter) (EvalValue, error) }
Expression is an expression which can be evaluated to a value.
type ForeachNode ¶
type ForeachNode struct { Collection string Nodes []Node Item string Index string Open string Close string Separator string }
ForeachNode is a node of foreach.
func (ForeachNode) Accept ¶
func (f ForeachNode) Accept(translator driver.Translator, p Parameter) (query string, args []any, err error)
Accept accepts parameters and returns query and arguments.
type GenericExecutor ¶
type GenericExecutor[T any] interface { // QueryContext executes the query and returns the direct result. // The args are for any placeholder parameters in the query. QueryContext(ctx context.Context, param Param) (T, error) // ExecContext executes a query without returning any rows. // The args are for any placeholder parameters in the query. ExecContext(ctx context.Context, param Param) (sql.Result, error) // Statement returns the statement of the current executor. Statement() *Statement // Session returns the session of the current executor. Session() Session // Use adds a middleware to the current executor. // The difference between Engine.Use and Executor.Use is only works for the current executor. Use(middlewares ...GenericMiddleware[T]) }
GenericExecutor is a generic executor.
type GenericManager ¶
type GenericManager[T any] interface { Object(v any) GenericExecutor[T] }
GenericManager is an interface for managing database operations.
func NewGenericManager ¶
func NewGenericManager[T any](manager Manager) GenericManager[T]
NewGenericManager returns a new GenericManager.
type GenericMiddleware ¶ added in v1.3.6
type GenericMiddleware[T any] interface { // QueryContext wraps the GenericQueryHandler. // The GenericQueryHandler is a function that accepts a context.Context, a query string and a slice of arguments. QueryContext(stmt *Statement, next GenericQueryHandler[T]) GenericQueryHandler[T] // ExecContext wraps the ExecHandler. // The ExecHandler is a function that accepts a context.Context, a query string and a slice of arguments. ExecContext(stmt *Statement, next ExecHandler) ExecHandler }
GenericMiddleware defines the middleware interface for the generic execution.
type GenericMiddlewareGroup ¶ added in v1.3.6
type GenericMiddlewareGroup[T any] []GenericMiddleware[T]
GenericMiddlewareGroup is a group of GenericMiddleware. It implements the GenericMiddleware interface.
func (GenericMiddlewareGroup[T]) ExecContext ¶ added in v1.3.6
func (m GenericMiddlewareGroup[T]) ExecContext(stmt *Statement, next ExecHandler) ExecHandler
ExecContext implements GenericMiddleware.
func (GenericMiddlewareGroup[T]) QueryContext ¶ added in v1.3.6
func (m GenericMiddlewareGroup[T]) QueryContext(stmt *Statement, next GenericQueryHandler[T]) GenericQueryHandler[T]
QueryContext implements GenericMiddleware.
type GenericQueryHandler ¶ added in v1.3.6
GenericQueryHandler defines the handler of the generic query.
type IncludeNode ¶
type IncludeNode struct {
// contains filtered or unexported fields
}
IncludeNode is a node of include. It includes another SQL.
func (*IncludeNode) Accept ¶
func (i *IncludeNode) Accept(translator driver.Translator, p Parameter) (query string, args []any, err error)
Accept accepts parameters and returns query and arguments.
type Manager ¶
Manager is an interface for managing database operations.
func ManagerFromContext ¶
ManagerFromContext returns the Manager from the context.
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper defines a set of statements.
func (*Mapper) Configuration ¶
func (m *Mapper) Configuration() *Configuration
type Mappers ¶
type Mappers struct {
// contains filtered or unexported fields
}
Mappers is a map of mappers.
func (*Mappers) Attribute ¶ added in v1.1.9
Attribute returns an attribute from the Mappers attributes.
func (*Mappers) Configuration ¶
func (m *Mappers) Configuration() *Configuration
Configuration represents a configuration of juice.
func (*Mappers) GetMapperByNamespace ¶ added in v1.4.6
func (*Mappers) GetStatement ¶
GetStatement try to one the statement from the Mappers with the given interface
func (*Mappers) GetStatementByID ¶
GetStatementByID returns a statement by id. If the statement is not found, an error is returned.
type Middleware ¶
type Middleware interface { // QueryContext wraps the QueryHandler. QueryContext(stmt *Statement, next QueryHandler) QueryHandler // ExecContext wraps the ExecHandler. ExecContext(stmt *Statement, next ExecHandler) ExecHandler }
Middleware is a wrapper of QueryHandler and ExecHandler.
type MiddlewareGroup ¶
type MiddlewareGroup []Middleware
MiddlewareGroup is a group of Middleware.
func (MiddlewareGroup) ExecContext ¶
func (m MiddlewareGroup) ExecContext(stmt *Statement, next ExecHandler) ExecHandler
ExecContext implements Middleware. Call ExecContext will call all the ExecContext of the middlewares in the group.
func (MiddlewareGroup) QueryContext ¶
func (m MiddlewareGroup) QueryContext(stmt *Statement, next QueryHandler) QueryHandler
QueryContext implements Middleware. Call QueryContext will call all the QueryContext of the middlewares in the group.
type Node ¶
type Node interface { // Accept accepts parameters and returns query and arguments. Accept(translator driver.Translator, p Parameter) (query string, args []any, err error) }
Node is a node of SQL.
func NewTextNode ¶ added in v1.2.9
type OsEnvValueProvider ¶
type OsEnvValueProvider struct{}
OsEnvValueProvider is a environment value provider that uses os.Getenv.
type OtherwiseNode ¶
type OtherwiseNode struct {
Nodes NodeGroup
}
OtherwiseNode is a node of otherwise. OtherwiseNode like else node, but it can not be used alone. If all WhenNode is false, the query of OtherwiseNode will be returned.
func (OtherwiseNode) Accept ¶
func (o OtherwiseNode) Accept(translator driver.Translator, p Parameter) (query string, args []any, err error)
Accept accepts parameters and returns query and arguments.
type Param ¶
type Param = any
Param is an alias of any type. It is used to represent the parameter of the statement and without type limitation.
func ParamFromContext ¶ added in v1.3.6
ParamFromContext returns the parameter from the context.
type ParamCtxInjectorExecutor ¶ added in v1.3.9
type ParamCtxInjectorExecutor struct {
Executor
}
ParamCtxInjectorExecutor is an executor that injects the param into the context. Which ensures that the param can be used in the middleware.
func (*ParamCtxInjectorExecutor) ExecContext ¶ added in v1.3.9
func (e *ParamCtxInjectorExecutor) ExecContext(ctx context.Context, param Param) (sql.Result, error)
ExecContext executes a query without returning any rows. The param are the placeholder collection for this query. The context is injected by the execContext.
func (*ParamCtxInjectorExecutor) QueryContext ¶ added in v1.3.9
func (e *ParamCtxInjectorExecutor) QueryContext(ctx context.Context, param Param) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The param are the placeholder collection for this query. The context is injected by the queryContext.
type ParamGroup ¶ added in v1.2.7
type ParamGroup []Parameter
ParamGroup is a group of parameters which implements the Parameter interface.
type Parameter ¶ added in v1.2.7
type Parameter interface { // Get returns the value of the named parameter with the type of reflect.Value. Get(name string) (reflect.Value, bool) }
Parameter is the interface that wraps the Get method. Get returns the value of the named parameter.
func NewParameter ¶ added in v1.2.7
NewParameter creates a new parameter with the given value.
type QueryHandler ¶
QueryHandler defines the handler of the query.
type RWLocker ¶ added in v1.3.3
type RWLocker interface { RLock() RUnlock() Lock() Unlock() }
RWLocker is a interface that can be used to lock、unlock and read lock、read unlock.
type ResultBinder ¶ added in v1.4.12
type ResultBinder interface {
BindTo(v reflect.Value) (BinderRouter, error)
}
ResultBinder is an interface that defines a single method BindTo. This method takes a reflect.Value and returns a BinderRouter and an error.
type ResultBinderGroup ¶ added in v1.4.12
type ResultBinderGroup []ResultBinder
ResultBinderGroup is a slice of ResultBinders.
func (ResultBinderGroup) BindTo ¶ added in v1.4.12
func (r ResultBinderGroup) BindTo(v reflect.Value) (BinderRouter, error)
BindTo method for a group of ResultBinders. It iterates over each binder in the group, calls its BindTo method, and merges the results into a single BinderRouter. If a key is found in more than one binder, it returns an error.
type ResultMap ¶
type ResultMap interface { // ResultTo maps the data from the SQL row to the provided reflect.Value. ResultTo(rv reflect.Value, row *sql.Rows) error }
ResultMap is an interface that defines a method for mapping database query results to Go data structures.
type RowResultMap ¶ added in v1.1.1
type RowResultMap struct{}
RowResultMap is a ResultMap that maps a rowDestination to a non-slice type.
type RowsResultMap ¶ added in v1.1.1
type RowsResultMap struct{}
RowsResultMap is a ResultMap that maps a rowDestination to a slice type.
type RowsScanner ¶ added in v1.1.2
RowsScanner scan sql.Rows to dest.
type SQLNode ¶
type SQLNode struct {
// contains filtered or unexported fields
}
SQLNode is a node of sql. SQLNode defines a SQL query.
type SelectFieldAliasNode ¶ added in v1.1.4
type SelectFieldAliasNode []*selectFieldAliasItem
SelectFieldAliasNode is a node of select field alias.
func (SelectFieldAliasNode) Accept ¶ added in v1.1.4
func (s SelectFieldAliasNode) Accept(_ driver.Translator, _ Parameter) (query string, args []any, err error)
Accept accepts parameters and returns query and arguments.
type Session ¶
type Session interface { QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) }
Session is a wrapper of sql.DB and sql.Tx
func SessionFromContext ¶
SessionFromContext returns the session from the context.
type SessionCtxInjectorExecutor ¶ added in v1.3.9
type SessionCtxInjectorExecutor struct {
Executor
}
SessionCtxInjectorExecutor is an executor that injects the session into the context. Which ensures that the session can be used in the middleware.
func (*SessionCtxInjectorExecutor) ExecContext ¶ added in v1.3.9
func (e *SessionCtxInjectorExecutor) ExecContext(ctx context.Context, param Param) (sql.Result, error)
ExecContext executes a query without returning any rows. The param are the placeholder collection for this query. The context is injected by the sessionContext.
func (*SessionCtxInjectorExecutor) QueryContext ¶ added in v1.3.9
func (e *SessionCtxInjectorExecutor) QueryContext(ctx context.Context, param Param) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The param are the placeholder collection for this query. The context is injected by the sessionContext.
type Setting ¶
type Setting struct { // The name of the setting. Name string `xml:"name,attr"` // The value of the setting. Value StringValue `xml:"value,attr"` }
Setting is a setting element.
type Settings ¶
type Settings map[string]StringValue
Settings is a collection of settings.
func (Settings) Get ¶
func (s Settings) Get(name string) StringValue
Get returns the value of the key.
type Statement ¶
type Statement struct { Nodes []Node // contains filtered or unexported fields }
Statement defines a sql statement.
func (*Statement) Configuration ¶
func (s *Statement) Configuration() *Configuration
Configuration returns the configuration of the statement.
func (*Statement) ExecHandler ¶ added in v1.3.2
func (s *Statement) ExecHandler() ExecHandler
ExecHandler returns the ExecHandler of the statement.
func (*Statement) ForWrite ¶
ForWrite returns true if the statement's Action is Insert, Update or Delete
func (*Statement) IsInsert ¶ added in v1.2.9
IsInsert returns true if the statement's Action is Insert
func (*Statement) QueryHandler ¶ added in v1.3.2
func (s *Statement) QueryHandler() QueryHandler
QueryHandler returns the QueryHandler of the statement.
type StringValue ¶
type StringValue string
StringValue is a string value which can be converted to other types.
func (StringValue) Bool ¶
func (s StringValue) Bool() bool
Bool returns true if the value is "true".
func (StringValue) Float64 ¶
func (s StringValue) Float64() float64
Float64 returns the value as float64.
func (StringValue) String ¶
func (s StringValue) String() string
String returns the value as string.
func (StringValue) Uint64 ¶ added in v1.3.9
func (s StringValue) Uint64() uint64
Uint64 returns the value as uint64.
func (StringValue) Unmarshaler ¶ added in v1.3.9
func (s StringValue) Unmarshaler(marshaller encoding.TextUnmarshaler) error
Unmarshaler unmarshals the value to given marshaller.
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
SyntaxError represents a syntax error. The error occurs when parsing the expression.
func (*SyntaxError) Unwrap ¶ added in v1.2.7
func (s *SyntaxError) Unwrap() error
Unwrap returns the underlying error.
type TextNode ¶
type TextNode struct {
// contains filtered or unexported fields
}
TextNode is a node of text. What is the difference between TextNode and pureTextNode? TextNode is used to replace parameters with placeholders. pureTextNode is used to avoid unnecessary parameter replacement.
type TimeoutMiddleware ¶
type TimeoutMiddleware struct{}
TimeoutMiddleware is a middleware that sets the timeout for the sql statement.
func (TimeoutMiddleware) ExecContext ¶
func (t TimeoutMiddleware) ExecContext(stmt *Statement, next ExecHandler) ExecHandler
ExecContext implements Middleware. ExecContext will set the timeout for the sql statement.
func (TimeoutMiddleware) QueryContext ¶
func (t TimeoutMiddleware) QueryContext(stmt *Statement, next QueryHandler) QueryHandler
QueryContext implements Middleware. QueryContext will set the timeout for the sql statement.
type TrimNode ¶
type TrimNode struct { Nodes []Node Prefix string PrefixOverrides []string Suffix string SuffixOverrides []string }
TrimNode is a node of trim.
type TxCacheManager ¶ added in v1.3.2
type TxCacheManager interface { TxManager Cache() cache.ScopeCache }
TxCacheManager defines a transactional scopeCache manager whose scopeCache can be accessed. All queries in the transaction will be cached. scopeCache.Flush() will be called after Commit() or Rollback().
func NewTxCacheManager ¶ added in v1.3.2
func NewTxCacheManager(manager TxManager, cache cache.ScopeCache) TxCacheManager
NewTxCacheManager returns a new TxCacheManager.
type TxManager ¶
type TxManager interface { Manager // Commit commits the transaction. Commit() error // Rollback rollbacks the transaction. // The rollback will be ignored if the tx has been committed. Rollback() error }
TxManager is a transactional mapper executor
type ValuesNode ¶ added in v1.1.4
type ValuesNode []*valueItem
ValuesNode is a node of values. only support for insert.
func (ValuesNode) Accept ¶ added in v1.1.4
func (v ValuesNode) Accept(translater driver.Translator, param Parameter) (query string, args []any, err error)
Accept accepts parameters and returns query and arguments.
type WhenNode ¶
type WhenNode = ConditionNode
WhenNode is a node of when. WhenNode like if node, but it can not be used alone. While one of WhenNode is true, the query of ChooseNode will be returned.