db

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDB

func GetDB() (db *sql.DB, err error)

GetDB returns a database ready to use It handles schema creation if needed

Types

type BookIndex

type BookIndex interface {
	// Insert a single book in the index
	InsertBook(book *ebook.Book) (string, error)
	// Check if book should be indexed, based on last modification time
	HasChanged(path string, lastMod time.Time) (bool, error)
}

BookIndex provides write access to the ebook index

type BookStore

type BookStore interface {
	// Retrieve recent books
	Recent() ([]ebook.Book, error)
	// Fetch a book by its ID
	Get(id string) (*ebook.Book, error)
	// Search an ebook by title, author or series
	Search(query string) ([]ebook.Book, error)
	GetLastModification(id string) (time.Time, error)
}

BookStore provides a read access to the ebook index

type CollectionStore

type CollectionStore interface {
	GetCollectionLastModification() (time.Time, error)
}

CollectionStore allow to query the collection as a whole

type Store

type Store struct {
	*sql.DB
	// contains filtered or unexported fields
}

Store wraps a database connection to act as a database abstraction layer

func New

func New(db *sql.DB) *Store

New creates a new DBStore

func (*Store) Get

func (store *Store) Get(id string) (*ebook.Book, error)

Get returns the book with given ID

func (*Store) GetCollectionLastModification

func (store *Store) GetCollectionLastModification() (time.Time, error)

GetCollectionLastModification will return the most recent mod_time

func (*Store) GetLastModification

func (store *Store) GetLastModification(id string) (time.Time, error)

GetLastModification returns the modification time for a given book

func (*Store) HasChanged

func (store *Store) HasChanged(path string, lastMod time.Time) (bool, error)

HasChanged will return false if the book is known and its modification date is not more recent that what is stored in the index. This will return true for any new book (not present in the index).

func (*Store) InsertBook

func (store *Store) InsertBook(book *ebook.Book) (string, error)

InsertBook will store a single book in the index

func (*Store) Recent

func (store *Store) Recent() ([]ebook.Book, error)

Recent retrieves recent books

func (*Store) Search

func (store *Store) Search(query string) ([]ebook.Book, error)

Search returns books matching the query This is a full-text search

Jump to

Keyboard shortcuts

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