Documentation
¶
Index ¶
- Constants
- func GetTxContext(ctx context.Context) context.Context
- func InClauseQuery(query string, args []interface{}) (string, []interface{}, error)
- func InClauseQueryTwoParams(query string, argOne, argTwo []interface{}) (string, []interface{}, error)
- func NewPGDriver(c Connector) (*sql.DB, error)
- func RollbackAndLogError(tx TxMgr, log *zap.Logger, query string)
- type Connector
- type PostgresqlDriver
- type PostgresqlMgr
- type RowMgr
- type Rows
- type SQLTx
- type Tx
- type TxHandler
- func (th TxHandler) Commit(ctx context.Context) error
- func (th TxHandler) ExecuteInClauseTx(ctx context.Context, query string, params []interface{}) (sql.Result, error)
- func (th TxHandler) ExecuteTx(ctx context.Context, query string, params ...string) (sql.Result, error)
- func (th TxHandler) SeclectQueryInClauseTx(ctx context.Context, obj interface{}, query string, params []interface{}) error
- func (th TxHandler) SeclectQueryTx(ctx context.Context, query string, obj interface{}, params ...interface{}) error
- type TxMgr
Constants ¶
const ( //TxKey context key TxKey key = iota )
Variables ¶
This section is empty.
Functions ¶
func GetTxContext ¶
GetTxContext return transaction context with tx object
func InClauseQuery ¶
InClauseQuery prepare args for In Clause query accept query and params return query , args and error
func InClauseQueryTwoParams ¶
func InClauseQueryTwoParams(query string, argOne, argTwo []interface{}) (string, []interface{}, error)
InClauseQueryTwoParams prepare args for In Clause query with two params (for complex query) accept query and params return query , args and error
func NewPGDriver ¶
NewPGDriver create new postgresql driver instance accept config and logger return instance of sql db
Types ¶
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector hold sql connection information
func NewConnector ¶
NewConnector return new connector
type PostgresqlDriver ¶
type PostgresqlDriver interface { Close() error Begin() (TxMgr, error) Query(query string, args ...interface{}) (RowMgr, error) }
PostgresqlDriver interface pgdriver.go
func NewPostgresqlMgr ¶
func NewPostgresqlMgr(pgDriver *sql.DB) PostgresqlDriver
NewPostgresqlMgr return new postgresql driver instance
type PostgresqlMgr ¶
PostgresqlMgr postgresql mgr
func (PostgresqlMgr) Begin ¶
func (pdi PostgresqlMgr) Begin() (TxMgr, error)
Begin sql tx return sql tx and error
func (PostgresqlMgr) Close ¶
func (pdi PostgresqlMgr) Close() error
Close close pg pool return error
type RowMgr ¶
type RowMgr interface { Scan(dest ...interface{}) error Next() bool Close() error Columns() ([]string, error) }
RowMgr interface pgdriver.go
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows encapsulate sql rows object
type SQLTx ¶
SQLTx encapsulate sql tx object
func (SQLTx) Exec ¶
Exec execute pg query (insert / update / delete ) accept query and params return sql exec results and error
type TxHandler ¶
type TxHandler struct {
PgDriver PostgresqlDriver
}
TxHandler object
func NewTxHandler ¶
func NewTxHandler(pgDriver PostgresqlDriver) *TxHandler
NewTxHandler return new tx handler with driver
func (TxHandler) ExecuteInClauseTx ¶
func (th TxHandler) ExecuteInClauseTx(ctx context.Context, query string, params []interface{}) (sql.Result, error)
ExecuteInClauseTx ExecuteTx execute query in tx
func (TxHandler) ExecuteTx ¶
func (th TxHandler) ExecuteTx(ctx context.Context, query string, params ...string) (sql.Result, error)
ExecuteTx execute query in tx