postgresstore

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package postgresstore provides a store.KV session backend built on the native celeris driver/postgres client. Sessions are persisted as BYTEA values under a configurable table (default "celeris_sessions").

The schema is created on first New call if it does not exist. A background cleanup goroutine periodically removes expired rows. Call Store.Close to stop the goroutine in tests or graceful shutdown paths.

TLS: driver/postgres does not yet support sslmode=require; use sslmode=disable on loopback / VPC deployments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// TableName is the target table. Default: "celeris_sessions".
	TableName string

	// CleanupInterval is how often expired rows are removed. Default:
	// 5 minutes. Zero disables cleanup entirely (rows still expire on
	// Get, but the table grows unbounded with never-read keys).
	CleanupInterval time.Duration

	// CleanupContext, when set, cancels the cleanup goroutine when
	// the context is done. If nil, Close is the only way to stop the
	// goroutine.
	CleanupContext context.Context

	// SkipSchemaInit, when true, suppresses the CREATE TABLE IF NOT
	// EXISTS statement issued by New. Use this when the DBA has
	// provisioned the schema out-of-band or the role does not have
	// DDL privileges.
	SkipSchemaInit bool
}

Options configure the PostgreSQL-backed session store.

type Store

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

Store is a store.KV backed by a PostgreSQL table. Implements store.PrefixDeleter via TRUNCATE (empty prefix clears the table).

func New

func New(ctx context.Context, pool *postgres.Pool, opts ...Options) (*Store, error)

New creates a PostgreSQL-backed session store. The schema is auto-initialized on first call unless [Options.SkipSchemaInit] is true. A background cleanup goroutine is started if [Options.CleanupInterval] > 0.

func (*Store) Close

func (s *Store) Close() error

Close stops the cleanup goroutine. Safe to call multiple times.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete implements store.KV.

func (*Store) DeletePrefix

func (s *Store) DeletePrefix(ctx context.Context, prefix string) error

DeletePrefix implements store.PrefixDeleter. An empty prefix TRUNCATEs the table; any other prefix runs a DELETE with a LIKE predicate. Prefix characters are escaped to avoid LIKE wildcards being interpreted.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) ([]byte, error)

Get implements store.KV.

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set implements store.KV. A ttl <= 0 stores NULL for expires_at (no expiry). Positive ttl converts to NOW() + INTERVAL.

Expires is passed as either a time.Time (positive TTL) or nil (no expiry). The celeris-postgres driver accepts those forms natively; passing sql.NullTime would fail with "unsupported argument type".

Jump to

Keyboard shortcuts

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