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 ¶
- func Close(db *sql.DB) error
- func GetDB(provider port.DatabaseProvider, ctx context.Context) *sql.DB
- func GetMigrationStatus(db *sql.DB) (int64, error)
- func NewConnection(ctx context.Context, dbPath string) (*sql.DB, error)
- func NewContentWhitelistRepository(db *sql.DB) repository.ContentWhitelistRepository
- func NewFavoriteRepository(db *sql.DB) repository.FavoriteRepository
- func NewFolderRepository(db *sql.DB) repository.FolderRepository
- func NewHistoryRepository(db *sql.DB) repository.HistoryRepository
- func NewLazyContentWhitelistRepository(provider port.DatabaseProvider) repository.ContentWhitelistRepository
- func NewLazyFavoriteRepository(provider port.DatabaseProvider) repository.FavoriteRepository
- func NewLazyFolderRepository(provider port.DatabaseProvider) repository.FolderRepository
- func NewLazyHistoryRepository(provider port.DatabaseProvider) repository.HistoryRepository
- func NewLazySessionRepository(provider port.DatabaseProvider) repository.SessionRepository
- func NewLazySessionStateRepository(provider port.DatabaseProvider) repository.SessionStateRepository
- func NewLazyTagRepository(provider port.DatabaseProvider) repository.TagRepository
- func NewLazyZoomRepository(provider port.DatabaseProvider) repository.ZoomRepository
- func NewSessionRepository(db *sql.DB) repository.SessionRepository
- func NewSessionStateRepository(db *sql.DB) repository.SessionStateRepository
- func NewTagRepository(db *sql.DB) repository.TagRepository
- func NewZoomRepository(db *sql.DB) repository.ZoomRepository
- func RunMigrations(ctx context.Context, db *sql.DB) error
- type LazyContentWhitelistRepository
- func (r *LazyContentWhitelistRepository) Add(ctx context.Context, domain string) error
- func (r *LazyContentWhitelistRepository) Contains(ctx context.Context, domain string) (bool, error)
- func (r *LazyContentWhitelistRepository) GetAll(ctx context.Context) ([]string, error)
- func (r *LazyContentWhitelistRepository) Remove(ctx context.Context, domain string) error
- type LazyDB
- type LazyFavoriteRepository
- func (r *LazyFavoriteRepository) Delete(ctx context.Context, id entity.FavoriteID) error
- func (r *LazyFavoriteRepository) FindByID(ctx context.Context, id entity.FavoriteID) (*entity.Favorite, error)
- func (r *LazyFavoriteRepository) FindByURL(ctx context.Context, url string) (*entity.Favorite, error)
- func (r *LazyFavoriteRepository) GetAll(ctx context.Context) ([]*entity.Favorite, error)
- func (r *LazyFavoriteRepository) GetByFolder(ctx context.Context, folderID *entity.FolderID) ([]*entity.Favorite, error)
- func (r *LazyFavoriteRepository) GetByShortcut(ctx context.Context, key int) (*entity.Favorite, error)
- func (r *LazyFavoriteRepository) Save(ctx context.Context, fav *entity.Favorite) error
- func (r *LazyFavoriteRepository) SetFolder(ctx context.Context, id entity.FavoriteID, folderID *entity.FolderID) error
- func (r *LazyFavoriteRepository) SetShortcut(ctx context.Context, id entity.FavoriteID, key *int) error
- func (r *LazyFavoriteRepository) UpdatePosition(ctx context.Context, id entity.FavoriteID, position int) error
- type LazyFolderRepository
- func (r *LazyFolderRepository) Delete(ctx context.Context, id entity.FolderID) error
- func (r *LazyFolderRepository) FindByID(ctx context.Context, id entity.FolderID) (*entity.Folder, error)
- func (r *LazyFolderRepository) GetAll(ctx context.Context) ([]*entity.Folder, error)
- func (r *LazyFolderRepository) GetChildren(ctx context.Context, parentID *entity.FolderID) ([]*entity.Folder, error)
- func (r *LazyFolderRepository) Save(ctx context.Context, folder *entity.Folder) error
- func (r *LazyFolderRepository) UpdatePosition(ctx context.Context, id entity.FolderID, position int) error
- type LazyHistoryRepository
- func (r *LazyHistoryRepository) Delete(ctx context.Context, id int64) error
- func (r *LazyHistoryRepository) DeleteAll(ctx context.Context) error
- func (r *LazyHistoryRepository) DeleteByDomain(ctx context.Context, domain string) error
- func (r *LazyHistoryRepository) DeleteOlderThan(ctx context.Context, before time.Time) error
- func (r *LazyHistoryRepository) FindByURL(ctx context.Context, url string) (*entity.HistoryEntry, error)
- func (r *LazyHistoryRepository) GetAllMostVisited(ctx context.Context) ([]*entity.HistoryEntry, error)
- func (r *LazyHistoryRepository) GetAllRecentHistory(ctx context.Context) ([]*entity.HistoryEntry, error)
- func (r *LazyHistoryRepository) GetDailyVisitCount(ctx context.Context, daysAgo string) ([]*entity.DailyVisitCount, error)
- func (r *LazyHistoryRepository) GetDomainStats(ctx context.Context, limit int) ([]*entity.DomainStat, error)
- func (r *LazyHistoryRepository) GetHourlyDistribution(ctx context.Context) ([]*entity.HourlyDistribution, error)
- func (r *LazyHistoryRepository) GetMostVisited(ctx context.Context, days int) ([]*entity.HistoryEntry, error)
- func (r *LazyHistoryRepository) GetRecent(ctx context.Context, limit, offset int) ([]*entity.HistoryEntry, error)
- func (r *LazyHistoryRepository) GetRecentSince(ctx context.Context, days int) ([]*entity.HistoryEntry, error)
- func (r *LazyHistoryRepository) GetStats(ctx context.Context) (*entity.HistoryStats, error)
- func (r *LazyHistoryRepository) IncrementVisitCount(ctx context.Context, url string) error
- func (r *LazyHistoryRepository) Save(ctx context.Context, entry *entity.HistoryEntry) error
- func (r *LazyHistoryRepository) Search(ctx context.Context, query string, limit int) ([]entity.HistoryMatch, error)
- type LazyRepositories
- type LazySessionRepository
- func (r *LazySessionRepository) Delete(ctx context.Context, id entity.SessionID) error
- func (r *LazySessionRepository) DeleteExitedBefore(ctx context.Context, cutoff time.Time) (int64, error)
- func (r *LazySessionRepository) DeleteOldestExited(ctx context.Context, keepCount int) (int64, error)
- func (r *LazySessionRepository) FindByID(ctx context.Context, id entity.SessionID) (*entity.Session, error)
- func (r *LazySessionRepository) GetActive(ctx context.Context) (*entity.Session, error)
- func (r *LazySessionRepository) GetRecent(ctx context.Context, limit int) ([]*entity.Session, error)
- func (r *LazySessionRepository) MarkEnded(ctx context.Context, id entity.SessionID, endedAt time.Time) error
- func (r *LazySessionRepository) Save(ctx context.Context, session *entity.Session) error
- type LazySessionStateRepository
- func (r *LazySessionStateRepository) DeleteSnapshot(ctx context.Context, sessionID entity.SessionID) error
- func (r *LazySessionStateRepository) GetAllSnapshots(ctx context.Context) ([]*entity.SessionState, error)
- func (r *LazySessionStateRepository) GetSnapshot(ctx context.Context, sessionID entity.SessionID) (*entity.SessionState, error)
- func (r *LazySessionStateRepository) GetTotalSnapshotsSize(ctx context.Context) (int64, error)
- func (r *LazySessionStateRepository) SaveSnapshot(ctx context.Context, state *entity.SessionState) error
- type LazyTagRepository
- func (r *LazyTagRepository) AssignToFavorite(ctx context.Context, tagID entity.TagID, favID entity.FavoriteID) error
- func (r *LazyTagRepository) Delete(ctx context.Context, id entity.TagID) error
- func (r *LazyTagRepository) FindByID(ctx context.Context, id entity.TagID) (*entity.Tag, error)
- func (r *LazyTagRepository) FindByName(ctx context.Context, name string) (*entity.Tag, error)
- func (r *LazyTagRepository) GetAll(ctx context.Context) ([]*entity.Tag, error)
- func (r *LazyTagRepository) GetForFavorite(ctx context.Context, favID entity.FavoriteID) ([]*entity.Tag, error)
- func (r *LazyTagRepository) RemoveFromFavorite(ctx context.Context, tagID entity.TagID, favID entity.FavoriteID) error
- func (r *LazyTagRepository) Save(ctx context.Context, tag *entity.Tag) error
- type LazyZoomRepository
- func (r *LazyZoomRepository) Delete(ctx context.Context, domain string) error
- func (r *LazyZoomRepository) Get(ctx context.Context, domain string) (*entity.ZoomLevel, error)
- func (r *LazyZoomRepository) GetAll(ctx context.Context) ([]*entity.ZoomLevel, error)
- func (r *LazyZoomRepository) Set(ctx context.Context, zoom *entity.ZoomLevel) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDB ¶ added in v0.22.0
GetDB returns the underlying *sql.DB for operations that need it directly. Returns nil if the database hasn't been initialized yet.
func GetMigrationStatus ¶
GetMigrationStatus returns the current migration version.
func NewConnection ¶
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.
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 (r *LazyContentWhitelistRepository) Add(ctx context.Context, domain string) error
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
NewLazyDB creates a new lazy database provider. The actual connection is not established until DB() is called.
func (*LazyDB) DB ¶ added in v0.22.0
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
IsInitialized returns true if the database has been initialized.
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 (r *LazyFavoriteRepository) Delete(ctx context.Context, id entity.FavoriteID) error
func (*LazyFavoriteRepository) FindByID ¶ added in v0.22.0
func (r *LazyFavoriteRepository) FindByID(ctx context.Context, id entity.FavoriteID) (*entity.Favorite, error)
func (*LazyFavoriteRepository) GetByFolder ¶ added in v0.22.0
func (*LazyFavoriteRepository) GetByShortcut ¶ 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) GetChildren ¶ added in v0.22.0
func (*LazyFolderRepository) UpdatePosition ¶ added in v0.22.0
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 (*LazyHistoryRepository) FindByURL ¶ added in v0.22.0
func (r *LazyHistoryRepository) FindByURL(ctx context.Context, url string) (*entity.HistoryEntry, error)
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 (r *LazyHistoryRepository) GetStats(ctx context.Context) (*entity.HistoryStats, error)
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 (r *LazyHistoryRepository) Save(ctx context.Context, entry *entity.HistoryEntry) error
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
type LazyRepositories struct {
History repository.HistoryRepository
Favorite repository.FavoriteRepository
Folder repository.FolderRepository
Tag repository.TagRepository
Zoom repository.ZoomRepository
Session repository.SessionRepository
SessionState repository.SessionStateRepository
Filter repository.ContentWhitelistRepository
}
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) DeleteExitedBefore ¶ added in v0.22.0
func (*LazySessionRepository) DeleteOldestExited ¶ added in v0.22.0
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 (*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 (r *LazySessionStateRepository) GetSnapshot(ctx context.Context, sessionID entity.SessionID) (*entity.SessionState, error)
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) FindByName ¶ added in v0.22.0
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
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