books

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package books contains book-related logic, and provides functions to search for books in a datastore. books also serves to expose an API to be used by servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SearchForTitles

func SearchForTitles(searchIn *SearchIn, searchBy *SearchBy) ([]string, error)

SearchForTitles works similar to Search but returns a list of titles (strings) instead of books. Titles can be then used to search for a specific book.

Types

type Book

type Book struct {
	ID            int     // A different number for each book.
	Title         string  // Book's title.
	Authors       string  // Book's authors.
	AverageRating float32 // Average rating (out of 5.)
	ISBN          string  // 10 digit ISBN.
	ISBN13        string  // 13 digit ISBN.
	LanguageCode  string  // 3-character language code.
	Pages         int     // Number of book's pages.
	RatingsCount  int     // Number of ratings (out of 5.)
	ReviewsCount  int     // Number of text reviews.
}

Book represents a searchable book object.

func Search(searchIn *SearchIn, searchBy *SearchBy) ([]*Book, error)

Search searchs in table and database specified in given SearchIn, and returns a list of books that match the parameters given in SearchBy.

func SearchByTitle

func SearchByTitle(searchIn *SearchIn, title string) ([]*Book, error)

SearchByTitle searchs in table and database specified in given SearchIn, and returns a list of books that match the given title.

type SearchBy

type SearchBy struct {
	TitleHas string // A sub-string that must exist in the title.

	Authors      []string // Must have at least one of these authors. Ignored if nil or empty.
	LanguageCode []string // Must be in at least one of these languages. Ignored if nil or empty.

	ISBN   string // 10 digit ISBN.
	ISBN13 string // 13 digit ISBN.

	RatingCeil        float32 // Rating must be less than or equal.
	RatingFloor       float32 // Rating must be higher than.
	PagesCeil         int     // Number of pages must be less than or equal.
	PagesFloor        int     // Number of pages must be higher than.
	RatingsCountCeil  int     // Number of ratings must be less than or equal.
	RatingsCountFloor int     // Number of ratings must be higher than.
	ReviewsCountCeil  int     // Number of reviews must be less than or equal.
	ReviewsCountFloor int     // Number of reviews must be higher than.
}

SearchBy is a set of parameters to use when searching for books in a datastore. Not all fields have to be specifed, a search can be performed using only a sub-set of the fields. To ignore a string field when searching, leave it empty, to ignore a number set it to < 0. For floor/ceil values floor is exclusive, ceil is inclusive.

type SearchIn

type SearchIn struct {
	Datastore *sql.DB // Datastore to search in.
	BookTable string  // Table to search in.
}

SearchIn contains the database and table's name to search in. Table's layout is specified in github.com/sudo-sturbia/bfr/internal/datastore.

Jump to

Keyboard shortcuts

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