database

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTableName = errors.New("database: invalid table name")

ErrInvalidTableName indicates that a configured table name is not a valid SQL identifier.

Functions

func InitSchema added in v0.0.6

func InitSchema(ctx context.Context, db *sqlx.DB, opts ...Option) error

InitSchema creates or updates the necessary tables and indexes for the database session service. It tracks schema changes in a migrations table to safely apply new columns or tables over time. It accepts the same Option values as NewDatabaseSessionService so that both calls target the same set of tables.

InitSchema is idempotent: it is safe to call on every application startup.

func NewDatabaseSession deprecated

func NewDatabaseSession(ctx context.Context, db *sqlx.DB, req session.CreateSessionRequest) (session.Session, error)

NewDatabaseSession creates a new session in the database using default table names.

Deprecated: prefer NewDatabaseSessionService, which supports custom table names via Option functions and integrates with InitSchema. NewDatabaseSession is retained for simple single-tenant use cases where the default table names are acceptable.

func NewDatabaseSessionService

func NewDatabaseSessionService(db *sqlx.DB, opts ...Option) (session.SessionService, error)

NewDatabaseSessionService creates a new SQL database-backed SessionService. The caller owns the *sqlx.DB and its driver configuration. SQLite and PostgreSQL are covered by this package's tests. By default it uses the table names "sessions", "events", and "turns". Use table Option functions to customise the names and avoid conflicts in shared databases. Use WithRunLocker to serialize Runner turns with an application-provided distributed lock. Returns an error if any configured table name is not a valid SQL identifier.

Types

type InvalidTableNameError added in v0.0.6

type InvalidTableNameError struct {
	Name string
}

InvalidTableNameError reports that a configured table name is not a valid SQL identifier.

func (*InvalidTableNameError) Error added in v0.0.6

func (e *InvalidTableNameError) Error() string

Error implements the error interface.

func (*InvalidTableNameError) Unwrap added in v0.0.6

func (e *InvalidTableNameError) Unwrap() error

Unwrap allows callers to match ErrInvalidTableName with errors.Is.

type Option added in v0.0.3

type Option func(*databaseSessionService)

Option is a functional option for configuring a DatabaseSessionService.

func WithEventsTable added in v0.0.6

func WithEventsTable(name string) Option

WithEventsTable overrides the events table name.

func WithMigrationsTable added in v0.0.6

func WithMigrationsTable(name string) Option

WithMigrationsTable overrides the schema migrations table name.

func WithRunLocker added in v0.0.6

func WithRunLocker(locker session.RunScopedLocker) Option

WithRunLocker overrides the locker used by Runner to serialize full turns. Database session services do not lock runs by default; multi-process deployments should provide a distributed implementation, such as PostgreSQL advisory locks or Redis.

func WithSessionsTable added in v0.0.3

func WithSessionsTable(name string) Option

WithSessionsTable overrides the sessions table name.

func WithTablePrefix added in v0.0.3

func WithTablePrefix(prefix string) Option

WithTablePrefix sets a prefix for all managed table names.

func WithTurnsTable added in v0.1.0

func WithTurnsTable(name string) Option

WithTurnsTable overrides the turns table name.

Jump to

Keyboard shortcuts

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