krabdb

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdvisoryUnlock added in v0.3.0

func AdvisoryUnlock(ctx context.Context, q sqlx.QueryerContext, id int64) (bool, error)

TryAdvisoryLock will release a previously-acquired exclusive session-level advisory lock. Returns true if the lock is successfully released. If the lock was not held, false is returned, and in addition, an SQL warning will be reported by the server.

https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS

func QuoteIdent

func QuoteIdent(s string) string

QuoteIdent escapes identifiers in PG.

func TryAdvisoryLock added in v0.3.0

func TryAdvisoryLock(ctx context.Context, q sqlx.QueryerContext, id int64) (bool, error)

TryAdvisoryLock will try to obtain session-level exclusive lock. This will either obtain the lock immediately and return true, or return false without waiting if the lock cannot be acquired immediately.

https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS

func TryAdvisoryXactLock

func TryAdvisoryXactLock(ctx context.Context, tx *sqlx.Tx, id int64) (bool, error)

TryAdvisoryXactLock will try to obtain transaction-level exclusive lock. It will not wait for the lock to become available. It will either obtain the lock immediately and return true, or return false if the lock cannot be acquired immediately. If acquired, is automatically released at the end of the current transaction and cannot be released explicitly.

https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS

func WithConnection

func WithConnection(f func(db *sqlx.DB) error) error

WithConnection connects to database and performs actions. After that connection is closed.

Types

type NullTransaction added in v0.3.0

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

NullTransaction represents fake transaction.

func (*NullTransaction) Commit added in v0.3.0

func (t *NullTransaction) Commit() error

func (*NullTransaction) ExecContext added in v0.3.0

func (t *NullTransaction) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*NullTransaction) Rollback added in v0.3.0

func (t *NullTransaction) Rollback() error

type Transaction added in v0.3.0

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

Transaction represents database transaction.

func (*Transaction) Commit added in v0.3.0

func (t *Transaction) Commit() error

func (*Transaction) ExecContext added in v0.3.0

func (t *Transaction) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*Transaction) Rollback added in v0.3.0

func (t *Transaction) Rollback() error

type TransactionExecerContext added in v0.3.0

type TransactionExecerContext interface {
	sqlx.ExecerContext

	Rollback() error
	Commit() error
}

func BeginTx added in v0.3.0

func BeginTx(ctx context.Context, db *sqlx.DB) (TransactionExecerContext, error)

BeginTx starts new transaction

func NewTx added in v0.3.0

func NewTx(ctx context.Context, db *sqlx.DB, createTransaction bool) (TransactionExecerContext, error)

NewTx is a helper that creates real transaction or null one based on createTransaction flag.

func NullTx added in v0.3.0

NullTx returns fake transaction to satisfy TransactionExecerContext interface

Jump to

Keyboard shortcuts

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