repo

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("record not found")

ErrNotFound is returned when a record is not found in the repository

Functions

func MapGenre

func MapGenre(tag string) string

MapGenre translates FB2 genre tag to human-readable name

func Translit

func Translit(s string) string

Translit converting Russian cyrillic characters to Latin approximation

Types

type BatchInserter

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

func (*BatchInserter) Add

func (bi *BatchInserter) Add(record *book.Book) error

func (*BatchInserter) Close

func (bi *BatchInserter) Close()

type Repo

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

func GetStorage

func GetStorage(path string) *Repo

func GetStorageWithConfig

func GetStorageWithConfig(path string, cfg *config.Config) *Repo

func (*Repo) Add

func (r *Repo) Add(record *book.Book) error

Add adds a single book

func (*Repo) AddBatch

func (r *Repo) AddBatch(records []*book.Book) error

AddBatch adds multiple books in a single transaction

func (*Repo) CheckpointWAL

func (r *Repo) CheckpointWAL() error

CheckpointWAL performs a WAL checkpoint to write all pending changes to the database file Use TRUNCATE mode for maximum efficiency: resets WAL file to zero bytes

func (*Repo) Close

func (r *Repo) Close() error

func (*Repo) CreateIndexes

func (r *Repo) CreateIndexes() error

func (*Repo) DropIndexes

func (r *Repo) DropIndexes() error

func (*Repo) GetAuthorByID

func (r *Repo) GetAuthorByID(id int64) (*book.Author, error)

func (*Repo) GetAuthors

func (r *Repo) GetAuthors() ([]book.Author, error)

func (*Repo) GetAuthorsByLetter

func (r *Repo) GetAuthorsByLetter(letters string) ([]book.Author, error)

func (*Repo) GetAuthorsWithBookCount

func (r *Repo) GetAuthorsWithBookCount() ([]book.AuthorWithBookCount, error)

func (*Repo) GetAuthorsWithBookCountByLetter

func (r *Repo) GetAuthorsWithBookCountByLetter(letters string) ([]book.AuthorWithBookCount, error)

func (*Repo) GetBookByID

func (r *Repo) GetBookByID(id int64) (*book.Book, error)

func (*Repo) GetBooks

func (r *Repo) GetBooks() ([]string, error)

func (*Repo) GetBooksByAuthorID

func (r *Repo) GetBooksByAuthorID(id int64) ([]book.Book, error)

func (*Repo) GetBooksByGenre

func (r *Repo) GetBooksByGenre(genre string, limit, offset int) ([]book.Book, int, error)

GetBooksByGenre returns books by genre with pagination

func (*Repo) GetBooksByLetter

func (r *Repo) GetBooksByLetter(letters string) ([]book.Book, error)

func (*Repo) GetBooksBySeriesID

func (r *Repo) GetBooksBySeriesID(seriesID int64) ([]book.Book, error)

GetBooksBySeriesID books by series

func (*Repo) GetGenres

func (r *Repo) GetGenres() ([]book.Genre, error)

func (*Repo) GetKeywords

func (r *Repo) GetKeywords() ([]book.Keyword, error)

GetKeywords Get all keywords

func (*Repo) GetLanguages added in v0.1.2

func (r *Repo) GetLanguages() ([]string, error)

GetLanguages returns a list of distinct languages from non-deleted books

func (*Repo) GetRecentBooks

func (r *Repo) GetRecentBooks(limit, offset int) ([]book.Book, int, error)

GetRecentBooks returns recently added books with pagination

func (*Repo) GetSeries

func (r *Repo) GetSeries() ([]book.SeriesInfo, error)

GetSeries Get all series

func (*Repo) InitCache

func (r *Repo) InitCache() error

func (*Repo) List

func (r *Repo) List() error

List placeholder to satisfy interface

func (*Repo) NewBatchInserter

func (r *Repo) NewBatchInserter(tx *sql.Tx) (*BatchInserter, error)

func (*Repo) Ping

func (r *Repo) Ping() error

func (*Repo) RebuildFTSIndex

func (r *Repo) RebuildFTSIndex() error

RebuildFTSIndex rebuilds the full-text search index for all books Updates the author field in books_fts to include properly concatenated author names

func (*Repo) Search

func (r *Repo) Search() error

Search placeholder to satisfy interface

func (*Repo) SearchBooks

func (r *Repo) SearchBooks(ctx context.Context, query string, limit, offset int, fields []string, languages []string) ([]book.BookSearchResult, error)

SearchBooks performs full-text search across book titles and authors Uses FTS5 for fast, ranked search results Optimized with single query including author JOIN (fixes N+1 query issue)

func (*Repo) SetBulkImportMode

func (r *Repo) SetBulkImportMode(enable bool) error

SetBulkImportMode configures the database for bulk import operations When enabled: disables WAL auto-checkpoint, increases cache to 256MB When disabled: restores normal checkpoint behavior and cache size

func (*Repo) SetFastMode

func (r *Repo) SetFastMode(enable bool) error

func (*Repo) SyncGenreDisplayNames

func (r *Repo) SyncGenreDisplayNames()

type Repository

type Repository interface {
	// Close closes the database connection
	Close() error

	// Health check
	Ping() error

	// Authors
	GetAuthors() ([]book.Author, error)
	GetAuthorsByLetter(letters string) ([]book.Author, error)
	GetAuthorByID(id int64) (*book.Author, error)
	GetAuthorsWithBookCount() ([]book.AuthorWithBookCount, error)
	GetAuthorsWithBookCountByLetter(letters string) ([]book.AuthorWithBookCount, error)

	// Books
	GetBooks() ([]string, error)
	GetBooksByLetter(letters string) ([]book.Book, error)
	GetBooksByAuthorID(id int64) ([]book.Book, error)
	GetBookByID(id int64) (*book.Book, error)
	GetRecentBooks(limit, offset int) ([]book.Book, int, error)
	GetBooksByGenre(genre string, limit, offset int) ([]book.Book, int, error)

	// SearchBooks performs full-text search across books by title and author
	// Returns results ranked by relevance (FTS5 rank)
	SearchBooks(ctx context.Context, query string, limit, offset int, fields []string, languages []string) ([]book.BookSearchResult, error)

	// Genres
	GetGenres() ([]book.Genre, error)

	// Languages
	GetLanguages() ([]string, error)

	// Write operations
	Add(record *book.Book) error
	Search() error
	List() error

	// RebuildFTSIndex rebuilds the full-text search index for all books
	RebuildFTSIndex() error
	CreateIndexes() error
	DropIndexes() error
	InitCache() error
	SetFastMode(enable bool) error

	// Bulk import optimizations
	SetBulkImportMode(enable bool) error
	CheckpointWAL() error
}

Repository defines the interface for data access operations

Jump to

Keyboard shortcuts

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