Documentation
¶
Index ¶
- Variables
- func InitSchema(ctx context.Context, db *sqlx.DB, opts ...Option) error
- func NewDatabaseSession(ctx context.Context, db *sqlx.DB, req session.CreateSessionRequest) (session.Session, error)deprecated
- func NewDatabaseSessionService(db *sqlx.DB, opts ...Option) (session.SessionService, error)
- type InvalidTableNameError
- type Option
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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
WithEventsTable overrides the events table name.
func WithMigrationsTable ¶ added in v0.0.6
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
WithSessionsTable overrides the sessions table name.
func WithTablePrefix ¶ added in v0.0.3
WithTablePrefix sets a prefix for all managed table names.
func WithTurnsTable ¶ added in v0.1.0
WithTurnsTable overrides the turns table name.