storage

package
v0.0.0-...-3205eea Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(db *sqlx.DB, runtimeConfig *wiki.RuntimeConfig) (*sqliteDb, error)

Init initializes the storage layer with an existing database connection and runtime config. The database connection should already have migrations applied via RunMigrations.

func RunMigrations

func RunMigrations(db *sqlx.DB, dialect Dialect) error

RunMigrations executes the database schema and any necessary migrations. It is idempotent and safe to run on both new and existing databases.

Types

type Dialect

type Dialect int

Dialect represents the database backend type.

const (
	DialectSQLite   Dialect = iota
	DialectPostgres         // reserved for Phase 3
)

type PreparedStatements

type PreparedStatements struct {
	SelectArticleByLatestRevisionStmt *sqlx.Stmt
	SelectArticleByRevisionHashStmt   *sqlx.Stmt
	SelectArticleByRevisionIDStmt     *sqlx.Stmt
	SelectUserScreennameStmt          *sqlx.Stmt
	SelectUserScreennameWithHashStmt  *sqlx.Stmt
}

PreparedStatements holds the prepared SQL statements used for database queries. This struct is exported to allow reuse in test utilities.

func InitializeStatements

func InitializeStatements(conn *sqlx.DB) (*PreparedStatements, error)

InitializeStatements prepares all the SQL statements needed for database operations. This function is exported to allow reuse in test utilities.

type SessionStore

type SessionStore struct {
	Options *sessions.Options
	// contains filtered or unexported fields
}

SessionStore is a gorilla/sessions backend backed by SQLite. It replaces the unmaintained michaeljs1990/sqlitestore package, reusing the app's existing *sqlx.DB (modernc.org/sqlite, pure Go).

Wire-compatible with sqlitestore: the cookie carries a securecookie-encoded integer session ID; the session payload is a separate securecookie-encoded blob in the session_data column.

func NewSessionStore

func NewSessionStore(db *sqlx.DB, path string, maxAge int, keyPairs ...[]byte) *SessionStore

NewSessionStore creates a SessionStore. keyPairs are passed to securecookie.CodecsFromPairs (hash key, optional encrypt key, …).

func (*SessionStore) Delete

func (s *SessionStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Delete removes the session from the database and expires the cookie.

func (*SessionStore) Get

func (s *SessionStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a cached session if present, otherwise calls New.

func (*SessionStore) New

func (s *SessionStore) New(r *http.Request, name string) (*sessions.Session, error)

New creates or loads a session. Decode errors from the cookie are returned (so callers can detect tampering), but DB load errors are silently swallowed — matching gorilla store convention (treat as "new session").

func (*SessionStore) Save

func (s *SessionStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save persists the session to the database and sets the cookie.

Jump to

Keyboard shortcuts

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