sqlkv

package
v1.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTableName is the default table name for the KV store
	DefaultTableName = "web_sessions"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect int

Dialect represents a specific SQL dialect configuration

const (
	// Generic is the default dialect (uses standard SQL as much as possible)
	Generic Dialect = iota
	// MySQL dialect
	MySQL
	// PostgreSQL dialect
	PostgreSQL
	// SQLite dialect
	SQLite
)

type Opts

type Opts struct {
	// TableName is the name of the table to use for the KV store (defaults to "web_sessions")
	TableName string
	// Dialect specifies which SQL dialect to use (defaults to Generic)
	Dialect Dialect
}

Opts contains options for configuring the KV store

type SqlKV

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

SqlKV implements the session.SqlKV interface using database/sql

func New

func New(db *sql.DB, opts *Opts) (*SqlKV, error)

New creates a new KV store backed by database/sql

func (*SqlKV) CreateTable

func (k *SqlKV) CreateTable(ctx context.Context) error

CreateTable creates the sessions table if it doesn't exist

func (*SqlKV) Delete

func (k *SqlKV) Delete(ctx context.Context, key string) error

Delete removes a key from the store

func (*SqlKV) GC

func (k *SqlKV) GC(ctx context.Context) (deleted int, _ error)

GC performs garbage collection, removing expired keys

func (*SqlKV) Get

func (k *SqlKV) Get(ctx context.Context, key string) (_ []byte, found bool, _ error)

Get retrieves a value by key, checking expiration

func (*SqlKV) RunGC

func (k *SqlKV) RunGC(ctx context.Context, interval time.Duration, logger *slog.Logger)

RunGC starts a background goroutine that performs garbage collection at regular intervals

func (*SqlKV) Set

func (k *SqlKV) Set(ctx context.Context, key string, expiresAt time.Time, value []byte) error

Set stores a key with a given value and expiration time, creating or updating as needed

Jump to

Keyboard shortcuts

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