sql

package
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheInvalidationUnsupported = errors.New("sql cache invalidation unsupported")

Functions

func QueryCacheKey

func QueryCacheKey(statement string, args ...any) string

Types

type CachedDB

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

func NewCachedDB

func NewCachedDB(cfg CachedDBConfig) (*CachedDB, error)

func (*CachedDB) BatchInsert

func (db *CachedDB) BatchInsert(ctx context.Context, batch capsql.BatchInsert) (capsql.Result, error)

func (*CachedDB) Begin

func (db *CachedDB) Begin(ctx context.Context) (capsql.Tx, error)

func (*CachedDB) CachedQuery

func (db *CachedDB) CachedQuery(ctx context.Context, key string, ttl time.Duration, load CachedLoader) ([]byte, error)

func (*CachedDB) CachedQueryRow

func (db *CachedDB) CachedQueryRow(ctx context.Context, key string, ttl time.Duration, load CachedLoader) ([]byte, error)

func (*CachedDB) Delete

func (db *CachedDB) Delete(ctx context.Context, key string) error

func (*CachedDB) Exec

func (db *CachedDB) Exec(ctx context.Context, query string, args ...any) (capsql.Result, error)

func (*CachedDB) Invalidate

func (db *CachedDB) Invalidate(ctx context.Context, key string) error

func (*CachedDB) Prepare

func (db *CachedDB) Prepare(ctx context.Context, query string) (capsql.Stmt, error)

func (*CachedDB) Query

func (db *CachedDB) Query(ctx context.Context, query string, args ...any) (capsql.Rows, error)

func (*CachedDB) QueryRow

func (db *CachedDB) QueryRow(ctx context.Context, query string, args ...any) capsql.Row

func (*CachedDB) WithTransaction

func (db *CachedDB) WithTransaction(ctx context.Context, fn func(context.Context, capsql.Tx) error) error

type CachedDBConfig

type CachedDBConfig struct {
	DB         capsql.DB
	Cache      capstore.CacheAside
	DefaultTTL time.Duration
}

type CachedLoader

type CachedLoader func(ctx context.Context, key string) ([]byte, error)

type Config

type Config struct {
	Name               string
	DSN                string
	Driver             string
	Dialect            capsql.Dialect
	DB                 *stdsql.DB
	Hooks              []capsql.QueryHook
	SlowQueryThreshold time.Duration
	SlowQueryHook      SlowQueryHook
	MaxOpenConns       int
	MaxIdleConns       int
	ConnMaxLifetime    time.Duration
	ConnMaxIdleTime    time.Duration
	PingTimeout        time.Duration
	HealthQuery        string
}

type DB

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

func New

func New(cfg Config) (*DB, error)

func (*DB) BatchInsert

func (db *DB) BatchInsert(ctx context.Context, batch capsql.BatchInsert) (capsql.Result, error)

func (*DB) Begin

func (db *DB) Begin(ctx context.Context) (capsql.Tx, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) Exec

func (db *DB) Exec(ctx context.Context, statement string, args ...any) (capsql.Result, error)

func (*DB) Prepare

func (db *DB) Prepare(ctx context.Context, statement string) (capsql.Stmt, error)

func (*DB) Query

func (db *DB) Query(ctx context.Context, statement string, args ...any) (capsql.Rows, error)

func (*DB) QueryRow

func (db *DB) QueryRow(ctx context.Context, statement string, args ...any) capsql.Row

func (*DB) ReportHealth

func (db *DB) ReportHealth(ctx context.Context) (caphealth.Report, error)

func (*DB) Stats

func (db *DB) Stats() stdsql.DBStats

func (*DB) WithTransaction

func (db *DB) WithTransaction(ctx context.Context, fn func(context.Context, capsql.Tx) error) error

type Factory

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

func NewFactory

func NewFactory(cfg FactoryConfig) (*Factory, error)

func (*Factory) BatchInsert

func (f *Factory) BatchInsert(ctx context.Context, batch capsql.BatchInsert) (capsql.Result, error)

func (*Factory) Begin

func (f *Factory) Begin(ctx context.Context) (capsql.Tx, error)

func (*Factory) DB

func (f *Factory) DB(name string) (capsql.DB, bool)

func (*Factory) Default

func (f *Factory) Default() capsql.DB

func (*Factory) Exec

func (f *Factory) Exec(ctx context.Context, query string, args ...any) (capsql.Result, error)

func (*Factory) MustDB

func (f *Factory) MustDB(name string) capsql.DB

func (*Factory) Prepare

func (f *Factory) Prepare(ctx context.Context, query string) (capsql.Stmt, error)

func (*Factory) Query

func (f *Factory) Query(ctx context.Context, query string, args ...any) (capsql.Rows, error)

func (*Factory) QueryRow

func (f *Factory) QueryRow(ctx context.Context, query string, args ...any) capsql.Row

func (*Factory) WithTransaction

func (f *Factory) WithTransaction(ctx context.Context, fn func(context.Context, capsql.Tx) error) error

type FactoryConfig

type FactoryConfig struct {
	Default   string
	Databases map[string]capsql.DB
}

type Router

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

func NewRouter

func NewRouter(cfg RouterConfig) (*Router, error)

func (*Router) BatchInsert

func (r *Router) BatchInsert(ctx context.Context, batch capsql.BatchInsert) (capsql.Result, error)

func (*Router) Begin

func (r *Router) Begin(ctx context.Context) (capsql.Tx, error)

func (*Router) Exec

func (r *Router) Exec(ctx context.Context, query string, args ...any) (capsql.Result, error)

func (*Router) Prepare

func (r *Router) Prepare(ctx context.Context, query string) (capsql.Stmt, error)

func (*Router) Query

func (r *Router) Query(ctx context.Context, query string, args ...any) (capsql.Rows, error)

func (*Router) QueryRow

func (r *Router) QueryRow(ctx context.Context, query string, args ...any) capsql.Row

func (*Router) WithTransaction

func (r *Router) WithTransaction(ctx context.Context, fn func(context.Context, capsql.Tx) error) error

type RouterConfig

type RouterConfig struct {
	Name    string
	Writer  capsql.DB
	Readers []capsql.DB
}

type SlowQueryEvent

type SlowQueryEvent struct {
	Metadata  capsql.QueryMetadata
	Threshold time.Duration
}

type SlowQueryHook

type SlowQueryHook func(ctx context.Context, event SlowQueryEvent)

Jump to

Keyboard shortcuts

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