postgres

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package postgres provides PostgreSQL storage for sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TTL time.Duration
}

Config configures the PostgreSQL session store.

type Store

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

Store implements session.Store using PostgreSQL.

func New

func New(db *sql.DB, cfg Config) *Store

New creates a new PostgreSQL session store.

func (*Store) Cleanup

func (s *Store) Cleanup(ctx context.Context) error

Cleanup removes expired sessions.

func (*Store) Close

func (s *Store) Close() error

Close stops the cleanup goroutine and waits for it to exit. It is safe to call Close even if StartCleanupRoutine was never called.

func (*Store) Create

func (s *Store) Create(ctx context.Context, sess *session.Session) error

Create persists a new session.

func (*Store) Delete

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

Delete removes a session.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*session.Session, error)

Get retrieves a session by ID. Returns nil, nil if not found or expired.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*session.Session, error)

List returns all non-expired sessions.

func (*Store) StartCleanupRoutine

func (s *Store) StartCleanupRoutine(interval time.Duration)

StartCleanupRoutine starts a background goroutine that periodically removes expired sessions. The goroutine is stopped when Close is called.

func (*Store) Touch

func (s *Store) Touch(ctx context.Context, id string) error

Touch updates LastActiveAt and extends ExpiresAt by the store's TTL.

func (*Store) UpdateState

func (s *Store) UpdateState(ctx context.Context, id string, state map[string]any) error

UpdateState merges state into the session's State map using JSONB concatenation.

Jump to

Keyboard shortcuts

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