session

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTx

func GetTx(ctx context.Context) any

GetTx retrieves a transaction from the context if it exists

func WithTx

func WithTx(ctx context.Context, tx any) context.Context

WithTx returns a new context with the given transaction value

Types

type DB added in v0.2.0

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

func (*DB) ConvertTx added in v0.2.0

func (db *DB) ConvertTx(ctx context.Context, tx *sql.Tx) Executor

func (*DB) GetDB added in v0.2.0

func (db *DB) GetDB(ctx context.Context) Executor

type DBWrapper added in v0.2.0

type DBWrapper[T any] interface {
	GetDB(ctx context.Context) T
}

func NewDB added in v0.2.0

func NewDB(db *sql.DB) DBWrapper[Executor]

func NewDBWrapper added in v0.2.0

func NewDBWrapper[T any](db Database[T]) DBWrapper[T]

type Database added in v0.2.0

type Database[T any] interface {
	GetDB(ctx context.Context) T
	ConvertTx(ctx context.Context, tx *sql.Tx) T
}

type Executor

type Executor interface {
	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Executor defines the common database operations that can be performed by both *sql.DB and *sql.Tx

type Session

type Session interface {
	WithTransaction(ctx context.Context, f func(ctx context.Context) error) error
}

func NewSession added in v0.2.0

func NewSession(db *sql.DB) Session

Jump to

Keyboard shortcuts

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