Documentation ¶
Index ¶
- Constants
- func GetDests(cols []string, respMap RowMap) []interface{}
- func ProcessQueryAndArgs(query string, reqMap RowMap) (string, []interface{})
- func QueryArgs(query string) (string, []string)
- type BeforeQueryFunc
- type ClientOption
- type Controller
- type FinalizerFunc
- type OperationType
- type ProcessRower
- type QueryHandler
- type RowMap
- type SqlTx
- type Transaction
- type TransactionBegin
- type Txer
- type WrappedTx
- func (wtx *WrappedTx) Commit(ctx context.Context) error
- func (wtx *WrappedTx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (wtx *WrappedTx) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (wtx *WrappedTx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (wtx *WrappedTx) Rollback(ctx context.Context) error
- func (wtx *WrappedTx) StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt
Constants ¶
const ( // ContextKeyTxOpened is a key of bool value in context. If true it means that transaction is opened. ContextKeyTxOpened contextKey = iota // ContextKeyOperationType is a key of value that describes the operation type. See consts OperationType*. ContextKeyOperationType // ContextKeyMethodName contains the method name from user interface. ContextKeyMethodName )
Variables ¶
This section is empty.
Functions ¶
func ProcessQueryAndArgs ¶
ProcessQueryAndArgs process query with named args to driver specific query.
Types ¶
type BeforeQueryFunc ¶ added in v0.7.0
type BeforeQueryFunc func(ctx context.Context, query string, req interface{}) (context.Context, FinalizerFunc)
BeforeQueryFunc is called before the query execution but after the preparing stmts. Returns the FinalizerFunc.
type ClientOption ¶ added in v0.7.0
type ClientOption func(ctrl *Controller)
ClientOption sets to controller the optional parameters for clients.
func BeforeQuery ¶ added in v0.7.0
func BeforeQuery(before ...BeforeQueryFunc) ClientOption
BeforeQuery sets the BeforeQueryFunc that is executed before the query.
type Controller ¶ added in v0.6.0
type Controller struct { BeforeQuery []BeforeQueryFunc sync.RWMutex CacheStmts map[string]*sql.Stmt }
Controller is a manager of query processing. Contains the stack of middlewares and cache of prepared statements.
func NewController ¶ added in v0.7.0
func NewController(options ...ClientOption) *Controller
NewController retunes a new object of Controller.
func (*Controller) PrepareStmt ¶ added in v0.8.0
func (ctrl *Controller) PrepareStmt(ctx context.Context, parent QueryHandler, qh QueryHandler, query string) (*sql.Stmt, error)
PrepareStmt returns the prepared statements. If stmt is presented in cache then it will be returned. if not, stmt will be prepared and put to cache.
type FinalizerFunc ¶ added in v0.7.0
FinalizerFunc is executed after the query execution.
type OperationType ¶ added in v0.9.0
type OperationType int
OperationType is a datatype for operation types.
const ( // OperationTypeQueryRow is a handler.Query operation and single row in response (like db.QueryRow). OperationTypeQueryRow OperationType = iota // OperationTypeQuery is a handler.Query operation. OperationTypeQuery // OperationTypeExec is a handler.Exec operation. OperationTypeExec // OperationTypeBegin is a start transaction operation, db.Begin(). OperationTypeBegin // OperationTypeCommit is a commits the transaction operation, tx.Commit(). OperationTypeCommit // OperationTypeRollback is a aborting the transaction operation, tx.Rollback(). OperationTypeRollback // OperationTypePrepare is a prepare statements operation. OperationTypePrepare // OperationTypeStmt is a operation of prepare statements on transaction. OperationTypeStmt )
func (OperationType) String ¶ added in v0.9.0
func (op OperationType) String() string
String returns the string name of operation.
type ProcessRower ¶ added in v0.5.0
type ProcessRower interface {
ProcessRow(rowMap RowMap)
}
ProcessRower is an interface that defines the signature of method of request or response that can allow to write pre processor of RowMap values.
type GetAuthorsReq struct { ID int64 `sql:"id"` Tags []int64 `sql:"tags"` } func (r GetAuthorsReq) ProcessRow(rowMap sal.RowMap) { rowMap.Set("tags", pq.Array(r.Tags)) }
As an argument method receives the RowMap object.
type QueryHandler ¶ added in v0.6.0
type QueryHandler interface { QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) }
QueryHandler describes the methods that are required to pass to constructor of the object implementation of user interface.
type RowMap ¶ added in v0.5.0
type RowMap map[string][]interface{}
RowMap contains mapping between column name in database and interface of value.
func (RowMap) GetByIndex ¶ added in v0.12.0
type SqlTx ¶ added in v0.13.0
type SqlTx interface { QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt Commit() error Rollback() error }
type Transaction ¶ added in v0.7.0
type Transaction interface { QueryHandler StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt Commit(ctx context.Context) error Rollback(ctx context.Context) error }
Transaction is an interface that describes the method to work with transaction object. Signature is similar to sql.Tx. The difference is Commit and Rollback methods. Its methods work with context.
type TransactionBegin ¶ added in v0.6.0
type TransactionBegin interface {
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}
TransactionBegin describes the signature of method of user interface to start transaction.
type Txer ¶ added in v0.10.0
type Txer interface {
Tx() Transaction
}
Txer describes the method to return implementation of Transaction interface.
type WrappedTx ¶ added in v0.10.0
type WrappedTx struct { Tx SqlTx // contains filtered or unexported fields }
WrappedTx is a struct that is an implementation of Transaction interface.
func NewWrappedTx ¶ added in v0.10.0
func NewWrappedTx(tx SqlTx, ctrl *Controller) *WrappedTx
NewWrappedTx returns the WrappedTx object.
func (*WrappedTx) ExecContext ¶ added in v0.10.0
func (wtx *WrappedTx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*WrappedTx) PrepareContext ¶ added in v0.10.0
PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*WrappedTx) QueryContext ¶ added in v0.10.0
func (wtx *WrappedTx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.