package store import ( "database/sql" "time" "github.com/alexedwards/scs/postgresstore" "github.com/alexedwards/scs/v2" ) const sessionsSchemaPostgres = ` CREATE TABLE IF NOT EXISTS sessions ( token TEXT PRIMARY KEY, data BYTEA NOT NULL, expiry TIMESTAMPTZ NOT NULL ); CREATE INDEX IF NOT EXISTS sessions_expiry_idx ON sessions (expiry); ` // applySessionsSchema creates the scs sessions table if missing. func applySessionsSchema(db *sql.DB) error { return applySchema(db, sessionsSchemaPostgres) } type sessionStopper interface { StopCleanup() } // SessionStore returns the scs store backed by this database. func (s *Store) SessionStore() scs.Store { return s.sessionStore } func (s *Store) initSessionStore(cleanupInterval time.Duration) { ps := postgresstore.NewWithCleanupInterval(s.db, cleanupInterval) s.sessionStore = ps s.sessionStopper = ps }