krabdb

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 12 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 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 Connect added in v0.4.0

func Connect(connectionString string) (*sqlx.DB, error)

func Quote added in v0.4.1

func Quote(o interface{}) string

Quote escapes values in PG.

func QuoteIdent

func QuoteIdent(s string) string

QuoteIdent escapes identifiers in PG.

public -> "public"

func QuoteIdentStrings added in v0.4.0

func QuoteIdentStrings(in []string) []string

QuoteIdentStrings escapes identifiers in PG.

func QuoteIdentWithDots added in v0.4.0

func QuoteIdentWithDots(s string) string

QuoteIdentWithDots escapes identifiers in PG.

public.test -> "public"."test"

func TryAdvisoryLock added in v0.3.0

func TryAdvisoryLock(ctx context.Context, q 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

Types

type Connection added in v0.4.0

type Connection interface {
	Get(f func(db DB) error) error
}

type DB added in v0.4.0

type DB interface {
	ExecerContext
	QueryerContext

	GetDatabase() *sqlx.DB
	NewTx(ctx context.Context, createTransaction bool) (TransactionExecerContext, error)
}

type DefaultConnection added in v0.4.0

type DefaultConnection struct{}

func (*DefaultConnection) Get added in v0.4.0

func (d *DefaultConnection) Get(f func(db DB) error) error

type ExecerContext added in v0.4.0

type ExecerContext interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

type Instance added in v0.4.0

type Instance struct {
	DB
	// contains filtered or unexported fields
}

func (*Instance) ExecContext added in v0.4.0

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

func (*Instance) GetDatabase added in v0.4.0

func (d *Instance) GetDatabase() *sqlx.DB

func (*Instance) NewTx added in v0.4.0

func (d *Instance) NewTx(ctx context.Context, createTransaction bool) (TransactionExecerContext, error)

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

func (*Instance) QueryContext added in v0.4.0

func (d *Instance) QueryContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)

func (*Instance) SelectContext added in v0.4.0

func (d *Instance) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

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 QueryerContext added in v0.4.0

type QueryerContext interface {
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
}

type SwitchableDatabaseConnection added in v0.9.0

type SwitchableDatabaseConnection struct {
	DatabaseName string
}

func (*SwitchableDatabaseConnection) Get added in v0.9.0

func (d *SwitchableDatabaseConnection) Get(f func(db DB) error) 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 {
	ExecerContext

	Rollback() error
	Commit() error
}

Jump to

Keyboard shortcuts

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