db

package module
v0.0.0-...-cced652 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

README

Kaliber/DB

golang GoDoc Go Report


Purpose

This internal package consolidates the functions needed to access the Calibre database. I wanted all this files together in one place to better design their interactions and perform tests as needed.

Usage

This internal package is not meant to be used from outside Kaliber.

Libraries

The following external libraries were used building kaliber/db:

Licence

    Copyright © 2019, 2024 M.Watermann, 10247 Berlin, Germany
                    All rights reserved
                EMail : <support@mwat.de>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

You should have received a copy of the GNU General Public License along with this program. If not, see the GNU General Public License for details.


GFDL

Documentation

Index

Constants

View Source
const (
	QoLangGerman  = uint8(0)
	QoLangEnglish = uint8(1)
)

Definition of the GUI language to use

View Source
const (
	QoLayoutList = uint8(0)
	QoLayoutGrid = uint8(1)
)

Definition of the layout type

View Source
const (
	QoThemeLight = uint8(0)
	QoThemeDark  = uint8(1)
)

Definition of the CSS theme to use

Variables

This section is empty.

Functions

func BookFieldVisible

func BookFieldVisible(aFieldname string) (bool, error)

BookFieldVisible returns whether `aFieldname` should be visible or not.

If `aFieldname` can't be found the function returns `true` and an error, otherwise the (boolean) `visible` value and `nil`.

`aFieldname` The name of the field/column to check.

func CalibreCachePath

func CalibreCachePath() string

CalibreCachePath returns the directory of the copied `Calibre` database.

func CalibreLibraryPath

func CalibreLibraryPath() string

CalibreLibraryPath returns the base directory of the `Calibre` library.

func CalibrePreferencesFile

func CalibrePreferencesFile() string

CalibrePreferencesFile returns the complete path-/filename of the `Calibre` library's preferences file.

func Init

func Init()

Init instantiates the database object.

This function should be called before using the database.

func MetaFieldValue

func MetaFieldValue(aSection, aField string) (interface{}, error)

MetaFieldValue returns the value of `aField` of `aSection`.

`aSection` Name of the field's metadata section.
`aField` Name of the data field within `aSection`.

func SQLtraceFile

func SQLtraceFile() string

SQLtraceFile returns the filename used for the optional logging of SQL queries.

func SetCalibreCachePath

func SetCalibreCachePath(aPath string) error

SetCalibreCachePath sets the directory of the `Calibre` database copy.

If `aPath` is an empty string or is a directory that can't be used or created the function returns an appropriate error, otherwise the return value is `nil`.

`aPath` is the directory path to use for caching the `Calibre` library.

func SetCalibreLibraryPath

func SetCalibreLibraryPath(aPath string) error

SetCalibreLibraryPath sets the base directory of the `Calibre` library.

If `aPath` is an empty string or is a directory that can't be used the function returns an appropriate error, otherwise the return value is `nil`.

`aPath` is the directory path where the `Calibre` library resides.

func SetSQLtraceFile

func SetSQLtraceFile(aFilename string)

SetSQLtraceFile sets the filename to use for logging SQL queries.

If the provided `aFilename` is empty the SQL logging gets disabled.

NOTE: Once the function was called with a valid `aFilename` argument any forther call will be ignored.

`aFilename` The tracefile to use, if empty tracing is disabled.

func VirtLibOptions

func VirtLibOptions(aSelected string) string

VirtLibOptions returns the SELECT/OPTIONs of the virtual libraries.

`aSelected` Name of the currently selected library.

Types

type TCustomColumn

type TCustomColumn struct {
	ID                    int
	Label, Name, Datatype string
}

TCustomColumn contains info about a user-defined data field.

The member fields should be considered R/O.

type TCustomColumnList

type TCustomColumnList []TCustomColumn

TCustomColumnList is a list of `TCustomColumn` instances.

type TDataBase

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

TDataBase An opaque structure providing the properties and methods to access the `Calibre` database.

func OpenDatabase

func OpenDatabase(aContext context.Context) (rDB *TDataBase, rErr error)

OpenDatabase returns a database connection.

`aContext` The current web request's context.

func (*TDataBase) Close

func (db *TDataBase) Close()

Close terminates the current database connection.

func (*TDataBase) QueryBy

func (db *TDataBase) QueryBy(aContext context.Context, aOptions *TQueryOptions) (rCount int, rList *TDocList, rErr error)

QueryBy returns all documents according to `aOptions`.

The method returns in `rCount` the number of documents found, in `rList` either `nil` or a list list of documents, in `rErr` either `nil` or the error occurred during the search.

`aContext` The current web request's context.
`aOptions` The options to configure the query.

func (*TDataBase) QueryCustomColumns

func (db *TDataBase) QueryCustomColumns(aContext context.Context) (*TCustomColumnList, error)

QueryCustomColumns returns data about user-defined columns in `Calibre`.

`aContext` The current web request's context.

func (*TDataBase) QueryDocMini

func (db *TDataBase) QueryDocMini(aContext context.Context, aID TID) (rDoc *TDocument)

QueryDocMini returns the document identified by `aID`.

This function fills only the document properties `ID`, `formats`, `path`, and `Title`. If a matching document could not be found the function returns `nil`.

`aContext` The current web request's context.
`aID` The document ID to lookup.

func (*TDataBase) QueryDocument

func (db *TDataBase) QueryDocument(aContext context.Context, aID TID) *TDocument

QueryDocument returns the `TDocument` identified by `aID`.

In case the document with `aID` can not be found the function returns `nil`.

`aContext` The current web request's context.
`aID` The document ID to lookup.

func (*TDataBase) QueryIDs

func (db *TDataBase) QueryIDs(aContext context.Context) (rList *TDocList, rErr error)

QueryIDs returns a list of documents with only the `ID` and `path` fields set.

This method is used by `thumbnails`.

`aContext` The current web request's context.

func (*TDataBase) QuerySearch

func (db *TDataBase) QuerySearch(aContext context.Context, aOptions *TQueryOptions) (rCount int, rList *TDocList, rErr error)

QuerySearch returns a list of documents matching the criteria in `aOptions`.

The function returns in `rCount` the number of documents found, in `rList` either `nil` or a list list of documents, in `rErr` either `nil` or an error occurred during the search.

`aContext` The current request's context.
`aOptions` The options to configure the query.

type TDocList

type TDocList []TDocument

TDocList is a list of `TDocument` instances.

func NewDocList

func NewDocList() *TDocList

NewDocList returns a new `TDocList` instance.

func (*TDocList) Add

func (dl *TDocList) Add(aDocument *TDocument) *TDocList

Add appends a document to the list of documents.

`aDocument` The document to add to the list.

type TDocument

type TDocument struct {
	ID TID

	ISBN string

	Pages int

	Rating int
	Size   int64

	Title string
	// contains filtered or unexported fields
}

TDocument represents a single document (e.g. book)

func NewDocument

func NewDocument() *TDocument

NewDocument returns a new `TDocument` instance.

func (*TDocument) AuthorList

func (doc *TDocument) AuthorList() string

AuthorList returns a CSV list of the document's author(s).

func (*TDocument) Authors

func (doc *TDocument) Authors() *TEntityList

Authors returns a list of ID/Name/URL author fields.

func (*TDocument) Comment

func (doc *TDocument) Comment() template.HTML

Comment returns the comments of the document.

func (*TDocument) Cover

func (doc *TDocument) Cover() string

Cover returns the URL path/filename for the document's cover image.

func (*TDocument) CoverAbs

func (doc *TDocument) CoverAbs(aRelative bool) (string, error)

CoverAbs returns the path/filename of the document's cover image.

If `aRelative` is `true` the function result is the path/filename relative to `CalibreLibraryPath()`, otherwise it's the document cover's complete path/filename.

`aRelative` Flag indicating a complete or relative path/filename

of the document's cover.

func (*TDocument) CoverFile

func (doc *TDocument) CoverFile() (string, error)

CoverFile returns the complete path/filename of the document's cover file.

func (doc *TDocument) DocLink() string

DocLink returns a link to this document's page.

func (*TDocument) Filename

func (doc *TDocument) Filename(aFormat string) string

Filename returns the path-/filename of the document's `aFormat`.

func (*TDocument) Files

func (doc *TDocument) Files() *TEntityList

Files returns a list of ID/Name/URL fields for doc format files.

func (*TDocument) Formats

func (doc *TDocument) Formats() *TEntityList

Formats returns a list of ID/Name/URL fields for doc formats.

func (*TDocument) Identifiers

func (doc *TDocument) Identifiers() *TEntityList

Identifiers returns a list of ID/Name/URL identifier fields.

func (*TDocument) Languages

func (doc *TDocument) Languages() *TEntityList

Languages returns an ID/Name/URL language struct.

func (*TDocument) LastModified

func (doc *TDocument) LastModified() string

LastModified returns the last-modified date/time of the document.

func (*TDocument) PubDate

func (doc *TDocument) PubDate() string

PubDate returns the document's formatted publication date.

func (*TDocument) Publisher

func (doc *TDocument) Publisher() *TEntity

Publisher returns an ID/Name/URL publisher struct.

func (*TDocument) Series

func (doc *TDocument) Series() *TEntity

Series returns an ID/Name/URL series struct.

func (*TDocument) SeriesIndex

func (doc *TDocument) SeriesIndex() string

SeriesIndex returns the document's series index as formatted string.

func (*TDocument) SetPath

func (doc *TDocument) SetPath(aPath string)

SetPath sets the document's file/path.

func (*TDocument) Tags

func (doc *TDocument) Tags() *TEntityList

Tags returns a list of ID/Name/URL tag fields.

func (*TDocument) Thumb

func (doc *TDocument) Thumb() string

Thumb returns the path-filename of the document's thumbnail image.

func (*TDocument) Timestamp

func (doc *TDocument) Timestamp() string

Timestamp returns the formatted `acquisition` property.

type TEntity

type TEntity struct {
	ID   TID    // database row ID
	Name string // name of the column/field
	URL  string // local URL to access this entity
}

TEntity is a basic entity structure.

type TEntityList

type TEntityList []TEntity

TEntityList is a list of entities

type TID

type TID = int

TID is the database index type (i.e. `int`).

type TQueryOptions

type TQueryOptions struct {
	ID          TID       // an entity ID to lookup
	Descending  bool      // sort direction
	Entity      string    // query for a certain entity (authors, publisher, series, tags)
	GuiLang     uint8     // GUI language
	Layout      uint8     // either `qoLayoutList` or `qoLayoutGrid`
	LimitLength uint      // number of documents per page
	LimitStart  uint      // starting number
	Matching    string    // text to lookup in all documents
	QueryCount  uint      // number of DB records matching the query options
	SortBy      TSortType // display order of documents (`qoSortByXXX`)
	Theme       uint8     // CSS presentation theme
	VirtLib     string    // virtual libraries
}

TQueryOptions hold properties configuring a query.

This type is used by the HTTP pagehandler when receiving a page request.

func NewQueryOptions

func NewQueryOptions(aDocsPerPage int) *TQueryOptions

NewQueryOptions returns a new `TQueryOptions` instance.

`aDocsPerPage` The number of documents per page to show.

func (*TQueryOptions) DecLimit

func (qo *TQueryOptions) DecLimit() *TQueryOptions

DecLimit decrements the LIMIT-start value.

func (*TQueryOptions) IncLimit

func (qo *TQueryOptions) IncLimit() *TQueryOptions

IncLimit increments the LIMIT values.

func (*TQueryOptions) Scan

func (qo *TQueryOptions) Scan(aString string) *TQueryOptions

Scan returns the options read from `aString`.

`aString` The value string to scan.

func (*TQueryOptions) SelectLanguageOptions

func (qo *TQueryOptions) SelectLanguageOptions() *TStringMap

SelectLanguageOptions returns a list of two SELECT/OPTIONs for the language choice.

func (*TQueryOptions) SelectLayoutOptions

func (qo *TQueryOptions) SelectLayoutOptions() *TStringMap

SelectLayoutOptions returns a list of SELECT/OPTIONs for the layout choice.

func (*TQueryOptions) SelectLimitOptions

func (qo *TQueryOptions) SelectLimitOptions() string

SelectLimitOptions returns a list of SELECT/OPTIONs for the limit (documents per page) choice.

func (*TQueryOptions) SelectOrderOptions

func (qo *TQueryOptions) SelectOrderOptions() *TStringMap

SelectOrderOptions returns a list of SELECT/OPTIONs for the order choice.

func (*TQueryOptions) SelectSortByOptions

func (qo *TQueryOptions) SelectSortByOptions() *TStringMap

SelectSortByOptions returns a list of SELECT/OPTIONs for the order choice.

func (*TQueryOptions) SelectThemeOptions

func (qo *TQueryOptions) SelectThemeOptions() *TStringMap

SelectThemeOptions returns a list of SELECT/OPTIONs for the theme choice.

func (*TQueryOptions) SelectVirtLibOptions

func (qo *TQueryOptions) SelectVirtLibOptions() string

SelectVirtLibOptions returns a list of SELECT/OPTIONs for the virtual library choice.

func (*TQueryOptions) String

func (qo *TQueryOptions) String() string

String returns the options as a `|` delimited string.

func (*TQueryOptions) Update

func (qo *TQueryOptions) Update(aRequest *http.Request) *TQueryOptions

Update returns a `TQueryOptions` instance with updated values read from the `aRequest` data.

`aRequest` The current HTTP request.

type TSearch

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

TSearch provides text search capabilities.

func NewSearch

func NewSearch(aSearchTerm string) *TSearch

NewSearch returns a new `TSearch` instance.

func (*TSearch) Clause

func (so *TSearch) Clause() (rWhere string)

Clause returns the produced WHERE clause.

func (*TSearch) Parse

func (so *TSearch) Parse() *TSearch

Parse returns the parsed search term(s).

func (*TSearch) String

func (so *TSearch) String() string

String returns a string field representation.

func (*TSearch) Where

func (so *TSearch) Where() string

Where returns the SQL code to use in the WHERE clause.

type TSortType

type TSortType uint8

TSortType is used for the sorting options.

type TStringMap

type TStringMap map[string]string

TStringMap is a map of strings indexed by string.

type TVirtLibList

type TVirtLibList map[string]string

TVirtLibList is the `virtual_libraries` JSON metadata section indexed by virt.library name.

func VirtualLibraryList

func VirtualLibraryList() (TVirtLibList, error)

VirtualLibraryList returns a list of virtual library definitions and SQL code to access them.

Jump to

Keyboard shortcuts

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