db

package
v0.0.0-...-fcf3058 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//TxKey context key
	TxKey key = iota
)

Variables

This section is empty.

Functions

func GetTxContext

func GetTxContext(ctx context.Context) context.Context

GetTxContext return transaction context with tx object

func InClauseQuery

func InClauseQuery(query string, args []interface{}) (string, []interface{}, error)

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

func NewPGDriver(c Connector) (*sql.DB, error)

NewPGDriver create new postgresql driver instance accept config and logger return instance of sql db

func RollbackAndLogError

func RollbackAndLogError(tx TxMgr, log *zap.Logger, query string)

RollbackAndLogError rollback tx with error logging accept tx,logger and query

Types

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector hold sql connection information

func NewConnector

func NewConnector(user, password, port, db, host, sqlType string) Connector

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

type PostgresqlMgr struct {
	PgPool *sql.DB
}

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

func (PostgresqlMgr) Query

func (pdi PostgresqlMgr) Query(query string, args ...interface{}) (RowMgr, error)

Query sql query accept query and args return rows and 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

func (Rows) Close

func (r Rows) Close() error

Close close sql rows return error

func (Rows) Columns

func (r Rows) Columns() ([]string, error)

Columns return query columns accept columns variables as pointers return error

func (Rows) Next

func (r Rows) Next() bool

Next check if there are additional rows return bool

func (Rows) Scan

func (r Rows) Scan(params ...interface{}) error

Scan scan query results accept columns variables as pointers return error

type SQLTx

type SQLTx struct {
	Tx *sql.Tx
}

SQLTx encapsulate sql tx object

func (SQLTx) Commit

func (stx SQLTx) Commit() error

Commit commmit sql tx return error

func (SQLTx) Exec

func (stx SQLTx) Exec(query string, args ...interface{}) (sql.Result, error)

Exec execute pg query (insert / update / delete ) accept query and params return sql exec results and error

func (SQLTx) Query

func (stx SQLTx) Query(query string, args ...interface{}) (RowMgr, error)

Query execute seletc query tx acceprt select query and args return sql rows and error

func (SQLTx) Rollback

func (stx SQLTx) Rollback() error

Rollback rollback sql tx return error

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx transaction object

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) Commit

func (th TxHandler) Commit(ctx context.Context) error

Commit accept context and commit a tx

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

func (TxHandler) SeclectQueryInClauseTx

func (th TxHandler) SeclectQueryInClauseTx(ctx context.Context, obj interface{}, query string, params []interface{}) error

SeclectQueryInClauseTx execute in Clause Tx

func (TxHandler) SeclectQueryTx

func (th TxHandler) SeclectQueryTx(ctx context.Context, query string, obj interface{}, params ...interface{}) error

SeclectQueryTx execute query in tx

type TxMgr

type TxMgr interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Commit() error
	Rollback() error
	Query(query string, args ...interface{}) (RowMgr, error)
}

TxMgr interface pgdriver.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL