Documentation
¶
Index ¶
- Variables
- func Context(ctx context.Context, db *sql.DB) context.Context
- func ContextWithTimeout(ctx context.Context, db *sql.DB, timeout int) (context.Context, context.CancelFunc)
- func DBIContext(ctx context.Context, db DBI) context.Context
- func DBIMiddleware(sqlDB *sql.DB) echo.MiddlewareFunc
- func ForContext(ctx context.Context) *sql.DB
- func GetPlaceholderFormat() sq.PlaceholderFormat
- func Middleware(db *sql.DB) echo.MiddlewareFunc
- func NewDBI(sdb *sql.DB) *db
- func SetPlaceholderFormat(format sq.PlaceholderFormat)
- func WithTx(ctx context.Context, opts *sql.TxOptions, fn func(tx *sql.Tx) error) error
- type DBI
- type DebugTx
- type FilterOptions
Constants ¶
This section is empty.
Variables ¶
TxOptionsRO read only transaction rules
Functions ¶
func 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
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 ¶
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 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.
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.
type DebugTx ¶ added in v0.1.6
DebugTx wraps a transaction with debug logging
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