sqlite

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package sqlite provides SQLite implementations of domain repositories.

Lazy Repository Infrastructure

This file contains lazy-loading repository wrappers that defer database initialization until first access. While currently unused (the application uses eager initialization via OpenDatabase in RunParallelDBWebKit), this infrastructure is kept for potential future optimization scenarios:

  • CLI commands that may not need database access
  • Further startup latency reduction by deferring DB init past first paint
  • Testing with mock DatabaseProvider implementations

The lazy wrappers implement the same repository interfaces as their eager counterparts, making them drop-in replacements when lazy initialization becomes beneficial.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(db *sql.DB) error

Close closes the database connection gracefully.

func GetDB added in v0.22.0

func GetDB(provider port.DatabaseProvider, ctx context.Context) *sql.DB

GetDB returns the underlying *sql.DB for operations that need it directly. Returns nil if the database hasn't been initialized yet.

func GetMigrationStatus

func GetMigrationStatus(db *sql.DB) (int64, error)

GetMigrationStatus returns the current migration version.

func NewConnection

func NewConnection(ctx context.Context, dbPath string) (*sql.DB, error)

NewConnection creates a new SQLite database connection with optimized settings. It creates the database directory if it doesn't exist and applies performance pragmas.

func NewContentWhitelistRepository

func NewContentWhitelistRepository(db *sql.DB) repository.ContentWhitelistRepository

NewContentWhitelistRepository creates a new SQLite-backed content whitelist repository.

func NewFavoriteRepository

func NewFavoriteRepository(db *sql.DB) repository.FavoriteRepository

NewFavoriteRepository creates a new SQLite-backed favorite repository.

func NewFolderRepository

func NewFolderRepository(db *sql.DB) repository.FolderRepository

NewFolderRepository creates a new SQLite-backed folder repository.

func NewHistoryRepository

func NewHistoryRepository(db *sql.DB) repository.HistoryRepository

NewHistoryRepository creates a new SQLite-backed history repository.

func NewLazyContentWhitelistRepository added in v0.22.0

func NewLazyContentWhitelistRepository(provider port.DatabaseProvider) repository.ContentWhitelistRepository

NewLazyContentWhitelistRepository creates a lazy-loading content whitelist repository.

func NewLazyFavoriteRepository added in v0.22.0

func NewLazyFavoriteRepository(provider port.DatabaseProvider) repository.FavoriteRepository

NewLazyFavoriteRepository creates a lazy-loading favorite repository.

func NewLazyFolderRepository added in v0.22.0

func NewLazyFolderRepository(provider port.DatabaseProvider) repository.FolderRepository

NewLazyFolderRepository creates a lazy-loading folder repository.

func NewLazyHistoryRepository added in v0.22.0

func NewLazyHistoryRepository(provider port.DatabaseProvider) repository.HistoryRepository

NewLazyHistoryRepository creates a lazy-loading history repository.

func NewLazySessionRepository added in v0.22.0

func NewLazySessionRepository(provider port.DatabaseProvider) repository.SessionRepository

NewLazySessionRepository creates a lazy-loading session repository.

func NewLazySessionStateRepository added in v0.22.0

func NewLazySessionStateRepository(provider port.DatabaseProvider) repository.SessionStateRepository

NewLazySessionStateRepository creates a lazy-loading session state repository.

func NewLazyTagRepository added in v0.22.0

func NewLazyTagRepository(provider port.DatabaseProvider) repository.TagRepository

NewLazyTagRepository creates a lazy-loading tag repository.

func NewLazyZoomRepository added in v0.22.0

func NewLazyZoomRepository(provider port.DatabaseProvider) repository.ZoomRepository

NewLazyZoomRepository creates a lazy-loading zoom repository.

func NewSessionRepository

func NewSessionRepository(db *sql.DB) repository.SessionRepository

func NewSessionStateRepository added in v0.21.0

func NewSessionStateRepository(db *sql.DB) repository.SessionStateRepository

NewSessionStateRepository creates a new session state repository.

func NewTagRepository

func NewTagRepository(db *sql.DB) repository.TagRepository

NewTagRepository creates a new SQLite-backed tag repository.

func NewZoomRepository

func NewZoomRepository(db *sql.DB) repository.ZoomRepository

NewZoomRepository creates a new SQLite-backed zoom repository.

func RunMigrations

func RunMigrations(ctx context.Context, db *sql.DB) error

RunMigrations applies all pending migrations to the database. Uses goose with embedded SQL files for automatic schema management.

Types

type LazyContentWhitelistRepository added in v0.22.0

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

LazyContentWhitelistRepository wraps a content whitelist repository with lazy database initialization.

func (*LazyContentWhitelistRepository) Add added in v0.22.0

func (*LazyContentWhitelistRepository) Contains added in v0.22.0

func (r *LazyContentWhitelistRepository) Contains(ctx context.Context, domain string) (bool, error)

func (*LazyContentWhitelistRepository) GetAll added in v0.22.0

func (*LazyContentWhitelistRepository) Remove added in v0.22.0

type LazyDB added in v0.22.0

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

LazyDB implements port.DatabaseProvider with lazy initialization. The database connection is created on first access, deferring the ~300-400ms WASM compilation and migration overhead until actually needed.

Currently unused: the application uses eager initialization via OpenDatabase in RunParallelDBWebKit. This implementation is kept for potential future use in scenarios where deferring database initialization past first paint provides additional latency benefits, or for CLI commands that may not need DB access.

func NewLazyDB added in v0.22.0

func NewLazyDB(dbPath string) *LazyDB

NewLazyDB creates a new lazy database provider. The actual connection is not established until DB() is called.

func (*LazyDB) Close added in v0.22.0

func (l *LazyDB) Close() error

Close closes the database connection if it was initialized.

func (*LazyDB) DB added in v0.22.0

func (l *LazyDB) DB(ctx context.Context) (*sql.DB, error)

DB returns the database connection, initializing it if necessary. This method is thread-safe and will only initialize once.

func (*LazyDB) IsInitialized added in v0.22.0

func (l *LazyDB) IsInitialized() bool

IsInitialized returns true if the database has been initialized.

func (*LazyDB) Path added in v0.22.0

func (l *LazyDB) Path() string

Path returns the database path.

type LazyFavoriteRepository added in v0.22.0

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

LazyFavoriteRepository wraps a favorite repository with lazy database initialization.

func (*LazyFavoriteRepository) Delete added in v0.22.0

func (*LazyFavoriteRepository) FindByID added in v0.22.0

func (*LazyFavoriteRepository) FindByURL added in v0.22.0

func (r *LazyFavoriteRepository) FindByURL(ctx context.Context, url string) (*entity.Favorite, error)

func (*LazyFavoriteRepository) GetAll added in v0.22.0

func (*LazyFavoriteRepository) GetByFolder added in v0.22.0

func (r *LazyFavoriteRepository) GetByFolder(ctx context.Context, folderID *entity.FolderID) ([]*entity.Favorite, error)

func (*LazyFavoriteRepository) GetByShortcut added in v0.22.0

func (r *LazyFavoriteRepository) GetByShortcut(ctx context.Context, key int) (*entity.Favorite, error)

func (*LazyFavoriteRepository) Save added in v0.22.0

func (*LazyFavoriteRepository) SetFolder added in v0.22.0

func (r *LazyFavoriteRepository) SetFolder(ctx context.Context, id entity.FavoriteID, folderID *entity.FolderID) error

func (*LazyFavoriteRepository) SetShortcut added in v0.22.0

func (r *LazyFavoriteRepository) SetShortcut(ctx context.Context, id entity.FavoriteID, key *int) error

func (*LazyFavoriteRepository) UpdatePosition added in v0.22.0

func (r *LazyFavoriteRepository) UpdatePosition(ctx context.Context, id entity.FavoriteID, position int) error

type LazyFolderRepository added in v0.22.0

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

LazyFolderRepository wraps a folder repository with lazy database initialization.

func (*LazyFolderRepository) Delete added in v0.22.0

func (*LazyFolderRepository) FindByID added in v0.22.0

func (*LazyFolderRepository) GetAll added in v0.22.0

func (r *LazyFolderRepository) GetAll(ctx context.Context) ([]*entity.Folder, error)

func (*LazyFolderRepository) GetChildren added in v0.22.0

func (r *LazyFolderRepository) GetChildren(ctx context.Context, parentID *entity.FolderID) ([]*entity.Folder, error)

func (*LazyFolderRepository) Save added in v0.22.0

func (r *LazyFolderRepository) Save(ctx context.Context, folder *entity.Folder) error

func (*LazyFolderRepository) UpdatePosition added in v0.22.0

func (r *LazyFolderRepository) UpdatePosition(ctx context.Context, id entity.FolderID, position int) error

type LazyHistoryRepository added in v0.22.0

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

LazyHistoryRepository wraps a history repository with lazy database initialization.

func (*LazyHistoryRepository) Delete added in v0.22.0

func (r *LazyHistoryRepository) Delete(ctx context.Context, id int64) error

func (*LazyHistoryRepository) DeleteAll added in v0.22.0

func (r *LazyHistoryRepository) DeleteAll(ctx context.Context) error

func (*LazyHistoryRepository) DeleteByDomain added in v0.22.0

func (r *LazyHistoryRepository) DeleteByDomain(ctx context.Context, domain string) error

func (*LazyHistoryRepository) DeleteOlderThan added in v0.22.0

func (r *LazyHistoryRepository) DeleteOlderThan(ctx context.Context, before time.Time) error

func (*LazyHistoryRepository) FindByURL added in v0.22.0

func (*LazyHistoryRepository) GetAllMostVisited added in v0.23.0

func (r *LazyHistoryRepository) GetAllMostVisited(ctx context.Context) ([]*entity.HistoryEntry, error)

func (*LazyHistoryRepository) GetAllRecentHistory added in v0.23.0

func (r *LazyHistoryRepository) GetAllRecentHistory(ctx context.Context) ([]*entity.HistoryEntry, error)

func (*LazyHistoryRepository) GetDailyVisitCount added in v0.22.0

func (r *LazyHistoryRepository) GetDailyVisitCount(ctx context.Context, daysAgo string) ([]*entity.DailyVisitCount, error)

func (*LazyHistoryRepository) GetDomainStats added in v0.22.0

func (r *LazyHistoryRepository) GetDomainStats(ctx context.Context, limit int) ([]*entity.DomainStat, error)

func (*LazyHistoryRepository) GetHourlyDistribution added in v0.22.0

func (r *LazyHistoryRepository) GetHourlyDistribution(ctx context.Context) ([]*entity.HourlyDistribution, error)

func (*LazyHistoryRepository) GetMostVisited added in v0.23.0

func (r *LazyHistoryRepository) GetMostVisited(ctx context.Context, days int) ([]*entity.HistoryEntry, error)

func (*LazyHistoryRepository) GetRecent added in v0.22.0

func (r *LazyHistoryRepository) GetRecent(ctx context.Context, limit, offset int) ([]*entity.HistoryEntry, error)

func (*LazyHistoryRepository) GetRecentSince added in v0.23.0

func (r *LazyHistoryRepository) GetRecentSince(ctx context.Context, days int) ([]*entity.HistoryEntry, error)

func (*LazyHistoryRepository) GetStats added in v0.22.0

func (*LazyHistoryRepository) IncrementVisitCount added in v0.22.0

func (r *LazyHistoryRepository) IncrementVisitCount(ctx context.Context, url string) error

func (*LazyHistoryRepository) Save added in v0.22.0

func (*LazyHistoryRepository) Search added in v0.22.0

func (r *LazyHistoryRepository) Search(ctx context.Context, query string, limit int) ([]entity.HistoryMatch, error)

type LazyRepositories added in v0.22.0

LazyRepositories holds all lazy-loaded repositories.

func NewLazyRepositories added in v0.22.0

func NewLazyRepositories(provider port.DatabaseProvider) *LazyRepositories

NewLazyRepositories creates all lazy repositories from a database provider.

type LazySessionRepository added in v0.22.0

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

LazySessionRepository wraps a session repository with lazy database initialization.

func (*LazySessionRepository) Delete added in v0.22.0

func (*LazySessionRepository) DeleteExitedBefore added in v0.22.0

func (r *LazySessionRepository) DeleteExitedBefore(ctx context.Context, cutoff time.Time) (int64, error)

func (*LazySessionRepository) DeleteOldestExited added in v0.22.0

func (r *LazySessionRepository) DeleteOldestExited(ctx context.Context, keepCount int) (int64, error)

func (*LazySessionRepository) FindByID added in v0.22.0

func (*LazySessionRepository) GetActive added in v0.22.0

func (r *LazySessionRepository) GetActive(ctx context.Context) (*entity.Session, error)

func (*LazySessionRepository) GetRecent added in v0.22.0

func (r *LazySessionRepository) GetRecent(ctx context.Context, limit int) ([]*entity.Session, error)

func (*LazySessionRepository) MarkEnded added in v0.22.0

func (r *LazySessionRepository) MarkEnded(ctx context.Context, id entity.SessionID, endedAt time.Time) error

func (*LazySessionRepository) Save added in v0.22.0

func (r *LazySessionRepository) Save(ctx context.Context, session *entity.Session) error

type LazySessionStateRepository added in v0.22.0

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

LazySessionStateRepository wraps a session state repository with lazy database initialization.

func (*LazySessionStateRepository) DeleteSnapshot added in v0.22.0

func (r *LazySessionStateRepository) DeleteSnapshot(ctx context.Context, sessionID entity.SessionID) error

func (*LazySessionStateRepository) GetAllSnapshots added in v0.22.0

func (r *LazySessionStateRepository) GetAllSnapshots(ctx context.Context) ([]*entity.SessionState, error)

func (*LazySessionStateRepository) GetSnapshot added in v0.22.0

func (*LazySessionStateRepository) GetTotalSnapshotsSize added in v0.22.0

func (r *LazySessionStateRepository) GetTotalSnapshotsSize(ctx context.Context) (int64, error)

func (*LazySessionStateRepository) SaveSnapshot added in v0.22.0

func (r *LazySessionStateRepository) SaveSnapshot(ctx context.Context, state *entity.SessionState) error

type LazyTagRepository added in v0.22.0

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

LazyTagRepository wraps a tag repository with lazy database initialization.

func (*LazyTagRepository) AssignToFavorite added in v0.22.0

func (r *LazyTagRepository) AssignToFavorite(ctx context.Context, tagID entity.TagID, favID entity.FavoriteID) error

func (*LazyTagRepository) Delete added in v0.22.0

func (r *LazyTagRepository) Delete(ctx context.Context, id entity.TagID) error

func (*LazyTagRepository) FindByID added in v0.22.0

func (r *LazyTagRepository) FindByID(ctx context.Context, id entity.TagID) (*entity.Tag, error)

func (*LazyTagRepository) FindByName added in v0.22.0

func (r *LazyTagRepository) FindByName(ctx context.Context, name string) (*entity.Tag, error)

func (*LazyTagRepository) GetAll added in v0.22.0

func (r *LazyTagRepository) GetAll(ctx context.Context) ([]*entity.Tag, error)

func (*LazyTagRepository) GetForFavorite added in v0.22.0

func (r *LazyTagRepository) GetForFavorite(ctx context.Context, favID entity.FavoriteID) ([]*entity.Tag, error)

func (*LazyTagRepository) RemoveFromFavorite added in v0.22.0

func (r *LazyTagRepository) RemoveFromFavorite(ctx context.Context, tagID entity.TagID, favID entity.FavoriteID) error

func (*LazyTagRepository) Save added in v0.22.0

func (r *LazyTagRepository) Save(ctx context.Context, tag *entity.Tag) error

type LazyZoomRepository added in v0.22.0

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

LazyZoomRepository wraps a zoom repository with lazy database initialization.

func (*LazyZoomRepository) Delete added in v0.22.0

func (r *LazyZoomRepository) Delete(ctx context.Context, domain string) error

func (*LazyZoomRepository) Get added in v0.22.0

func (r *LazyZoomRepository) Get(ctx context.Context, domain string) (*entity.ZoomLevel, error)

func (*LazyZoomRepository) GetAll added in v0.22.0

func (r *LazyZoomRepository) GetAll(ctx context.Context) ([]*entity.ZoomLevel, error)

func (*LazyZoomRepository) Set added in v0.22.0

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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