sql

package
v0.0.0-...-0a06464 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseSQLConn

type DatabaseSQLConn interface {
	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

Interface for connections that use database/sql.

type GCOptions

type GCOptions struct {
	Logger logger.Logger

	// Query that must atomically update the "last cleanup time" in the metadata table, but only if the garbage collector hasn't run already.
	// The caller will check the nuber of affected rows. If zero, it assumes that the GC has ran too recently, and will not proceed to delete expired records.
	// The query receives one parameter that is the last cleanup interval, in milliseconds.
	UpdateLastCleanupQuery string

	// Name of the parameter passed to the UpdateLeastCleanupQuery query, to use named parameters (via `sql.Named`). The parameter is the time interval.
	// If empty, assumes the parameter is positional and not named.
	// This is ignored when using the pgx querier.
	UpdateLastCleanupQueryParameterName string

	// Query that performs the cleanup of all expired rows.
	DeleteExpiredValuesQuery string

	// Interval to perfm the cleanup.
	CleanupInterval time.Duration

	// Database connection when using pgx.
	DBPgx PgxConn
	// Database connection when using database/sql.
	DBSql DatabaseSQLConn
}

type GarbageCollector

type GarbageCollector interface {
	CleanupExpired() error
	io.Closer
}

func ScheduleGarbageCollector

func ScheduleGarbageCollector(opts GCOptions) (GarbageCollector, error)

type PgxConn

type PgxConn interface {
	Begin(context.Context) (pgx.Tx, error)
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
}

Interface for connections that use pgx.

Jump to

Keyboard shortcuts

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