krabdb

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdvisoryUnlock

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 Quote

func Quote(o any) string

Quote escapes values in PG.

func QuoteIdent

func QuoteIdent(s string) string

QuoteIdent escapes identifiers in PG.

public -> "public"

func QuoteIdentStrings

func QuoteIdentStrings(in []string) []string

QuoteIdentStrings escapes identifiers in PG.

func QuoteIdentWithDots

func QuoteIdentWithDots(s string) string

QuoteIdentWithDots escapes identifiers in PG.

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

func TryAdvisoryLock

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 DB

type DB interface {
	ExecerContext
	QueryerContext

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

type ExecerContext

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

type Instance

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

func (*Instance) ExecContext

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

func (*Instance) GetDatabase

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

func (*Instance) NewTx

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

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

func (*Instance) SelectContext

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

type NullTransaction

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

NullTransaction represents fake transaction.

func (*NullTransaction) Commit

func (t *NullTransaction) Commit() error

func (*NullTransaction) ExecContext

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

func (*NullTransaction) Rollback

func (t *NullTransaction) Rollback() error

type QueryerContext

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

type Transaction

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

Transaction represents database transaction.

func (*Transaction) Commit

func (t *Transaction) Commit() error

func (*Transaction) ExecContext

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

func (*Transaction) Rollback

func (t *Transaction) Rollback() error

type TransactionExecerContext

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