stmtcache

package
v0.0.0-...-9e054ec Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package stmtcache provides a cache for prepared statements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T comparable] struct {
	// contains filtered or unexported fields
}

Cache holds prepared statements which are retrieved by a comparable key. Since prepared statements may have a non-trivial cost or be a limited resource in the target database, so we want the Cache to have a one-to-one lifetime with the underlying database pool.

func New

func New[T comparable](ctx *stopper.Context, db *sql.DB, size int) *Cache[T]

New constructs a Cache for the pool.

func (*Cache[T]) Diagnostic

func (c *Cache[T]) Diagnostic(_ context.Context) any

Diagnostic implements [diag.Diagnostic]. It returns the capacity and size of the cache.

func (*Cache[T]) Prepare

func (c *Cache[T]) Prepare(
	ctx context.Context, db any, key T, gen func() (string, error),
) (*sql.Stmt, error)

Prepare returns or constructs a new prepared statement. If db is a *sql.Tx, the statement will be attached to the transaction.

Jump to

Keyboard shortcuts

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