database

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: BSD-3-Clause Imports: 14 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TxOptionsRO = &sql.TxOptions{Isolation: 0, ReadOnly: true}

TxOptionsRO read only transaction rules

Functions

func Context

func Context(ctx context.Context, db *sql.DB) context.Context

Context adds db connection to context for immediate use

func ContextWithTimeout

func ContextWithTimeout(
	ctx context.Context, db *sql.DB, timeout int) (context.Context, context.CancelFunc)

ContextWithTimeout returns a context with query timeout

func DBIContext added in v0.1.4

func DBIContext(ctx context.Context, db DBI) context.Context

DBIContext adds db connection to context for immediate use

func DBIMiddleware added in v0.1.4

func DBIMiddleware(sqlDB *sql.DB) echo.MiddlewareFunc

DBIMiddleware creates a new DBI instance per request

func ForContext

func ForContext(ctx context.Context) *sql.DB

ForContext pulls *sql.DB obj for context

func GetPlaceholderFormat added in v0.1.2

func GetPlaceholderFormat() sq.PlaceholderFormat

GetPlaceholderFormat will return the currently configured placeholder format. It can be used to set the format at the application level. This helps keep things easier to change database backends in the future. Will panic if no value is set, though the default value is "squirrel.Question" (question mark)

func Middleware

func Middleware(db *sql.DB) echo.MiddlewareFunc

Middleware will place the stripe client in the request context

func NewDBI added in v0.1.4

func NewDBI(sdb *sql.DB) *db

NewDB returns a new DB struct

func SetPlaceholderFormat added in v0.1.2

func SetPlaceholderFormat(format sq.PlaceholderFormat)

SetPlaceholderFormat will set the application level placeholder format. This should be called early in your applications startup to avoid any issues with queries depending on this value.

func WithTx

func WithTx(ctx context.Context, opts *sql.TxOptions, fn func(tx *sql.Tx) error) error

WithTx calls a function wrapped in a database transaction

Types

type DBI added in v0.1.4

type DBI interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	CommitTx() error
	RollbackTx() error
	WillCommit() bool
	EnableCommit() bool
	DisableCommit() bool
	GetDB() *sql.DB
	HasActiveTransaction() bool
}

DBI is an interface to provide database access. This allows you to run through many queries in a single transaction. Also allows you to enable commit, commit, then disable it again for cases when you MUST write to the db.

func DBIForContext added in v0.1.4

func DBIForContext(ctx context.Context) DBI

DBIForContext pulls *sql.DB obj for context

type DebugTx added in v0.1.6

type DebugTx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

DebugTx wraps a transaction with debug logging

func (*DebugTx) Commit added in v0.1.6

func (dt *DebugTx) Commit() error

func (*DebugTx) Rollback added in v0.1.6

func (dt *DebugTx) Rollback() error

type FilterOptions

type FilterOptions struct {
	Filter  sq.Sqlizer
	Limit   int
	Offset  int
	OrderBy string

	Metadata map[string]any // Used for misc. data passing
}

FilterOptions is a simple helper for sql filtering

func (*FilterOptions) GetBuilder

func (f *FilterOptions) GetBuilder(filter sq.Sqlizer) sq.SelectBuilder

GetBuilder returns a squirrel SelectBuilder based on options

Source Files

  • dbi.go
  • middleware.go
  • options.go
  • sql.go
  • test_helpers.go

Jump to

Keyboard shortcuts

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