Versions in this module Expand all Collapse all v0 v0.1.0 Dec 25, 2023 Changes in this version + var ErrNoConnectionBound = errors.New("no DB connection bound for the context") + var ErrNoTenantBound = errors.New("no tenant bound for the context") + func Middleware[DB DBish, Conn Connish](n *Nagaya[DB, Conn], opts ...MiddlewareOption) func(http.Handler) http.Handler + func WithTenant(ctx context.Context, tenant Tenant) context.Context + type ChangeTenantError struct + func (e *ChangeTenantError) Error() string + func (e *ChangeTenantError) Tenant() Tenant + func (e *ChangeTenantError) Unwrap() error + type Connish interface + BeginTx func(context.Context, *sql.TxOptions) (*sql.Tx, error) + Close func() error + ExecContext func(context.Context, string, ...any) (sql.Result, error) + PingContext func(context.Context) error + PrepareContext func(context.Context, string) (*sql.Stmt, error) + QueryContext func(context.Context, string, ...any) (*sql.Rows, error) + QueryRowContext func(context.Context, string, ...any) *sql.Row + type DBish interface + BeginTx func(context.Context, *sql.TxOptions) (*sql.Tx, error) + Close func() error + ExecContext func(context.Context, string, ...any) (sql.Result, error) + PingContext func(context.Context) error + PrepareContext func(context.Context, string) (*sql.Stmt, error) + QueryContext func(context.Context, string, ...any) (*sql.Rows, error) + QueryRowContext func(context.Context, string, ...any) *sql.Row + SetConnMaxIdleTime func(time.Duration) + SetConnMaxLifetime func(time.Duration) + SetMaxIdleConns func(int) + SetMaxOpenConns func(int) + Stats func() sql.DBStats + type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error) + type GenerateRequestIDError struct + func (e *GenerateRequestIDError) Error() string + func (e *GenerateRequestIDError) Unwrap() error + type GetConnFn func(ctx context.Context, db DB) (Conn, error) + type MiddlewareOption func(cfg *middlewareConfig) + func GetTenantFromHeader(headerName string) MiddlewareOption + func WithChangeTenantErrorHandler(handler ErrorHandler) MiddlewareOption + func WithErrorHandler(handler ErrorHandler) MiddlewareOption + func WithGenerateRequestIDErrorHandler(handler ErrorHandler) MiddlewareOption + func WithGetTenantFn(fn func(r *http.Request) (Tenant, bool)) MiddlewareOption + func WithNoTenantBoundErrorHandler(handler ErrorHandler) MiddlewareOption + func WithObtainConnectionErrorHandler(handler ErrorHandler) MiddlewareOption + func WithRequestIDGenerator(gen RequestIDGenerator) MiddlewareOption + func WithTimeout(dur time.Duration) MiddlewareOption + type Nagaya struct + func NewStd(db *sql.DB) *Nagaya[*sql.DB, *sql.Conn] + func New[DB DBish, Conn Connish](db DB, getConn GetConnFn[DB, Conn]) *Nagaya[DB, Conn] + func (n *Nagaya[DB, Conn]) ObtainConnection(ctx context.Context) (conn Conn, err error) + type ObtainConnectionError struct + func (e *ObtainConnectionError) Error() string + func (e *ObtainConnectionError) Unwrap() error + type RequestIDGenerator interface + GenerateID func(ctx context.Context, r *http.Request) (string, error) + type RequestIDGeneratorFunc func(ctx context.Context, r *http.Request) (string, error) + func (f RequestIDGeneratorFunc) GenerateID(ctx context.Context, r *http.Request) (string, error) + type Tenant string + func TenantFromContext(ctx context.Context) (Tenant, bool)