quotes

package module
v0.0.0-...-60831de Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 17 Imported by: 2

README

#Quotes

A small database/sql piece for CRUD + random lookup of quotes. Works great with the ultimateq irc bot.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Quote

type Quote struct {
	ID     int
	Date   time.Time
	Author string
	Quote  string

	Upvotes   int
	Downvotes int
}

Quote is for serializing to and from the sqlite database.

type QuoteDB

type QuoteDB struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

QuoteDB provides file storage of quotes via an sqlite database.

func OpenDB

func OpenDB(filename, webAuth string) (*QuoteDB, error)

OpenDB opens the database at the location requested.

func (*QuoteDB) AddQuote

func (q *QuoteDB) AddQuote(author, quote string) (id int64, err error)

AddQuote adds a quote to the database.

func (*QuoteDB) Close

func (q *QuoteDB) Close() error

Close the database file.

func (*QuoteDB) DelQuote

func (q *QuoteDB) DelQuote(id int) (bool, error)

DelQuote deletes a quote by id.

func (*QuoteDB) Downvote

func (q *QuoteDB) Downvote(id int, voter string) (bool, error)

Downvote returns true iff the upvote was applied, if it was not applied it's because the user already has a vote for that quote

func (*QuoteDB) EditQuote

func (q *QuoteDB) EditQuote(id int, quote string) (bool, error)

EditQuote edits a quote by id.

func (*QuoteDB) GetAll

func (q *QuoteDB) GetAll(filterLow bool) ([]Quote, error)

GetAll quotes

func (*QuoteDB) GetQuote

func (q *QuoteDB) GetQuote(id int) (quote Quote, err error)

GetQuote gets a specific quote by id.

func (*QuoteDB) NQuotes

func (q *QuoteDB) NQuotes() int

NQuotes returns the number of quotes in the database.

func (*QuoteDB) RandomQuote

func (q *QuoteDB) RandomQuote() (quote Quote, err error)

RandomQuote gets a random existing quote.

func (*QuoteDB) StartServer

func (q *QuoteDB) StartServer(address string)

StartServer starts a webserver to listen on.

func (*QuoteDB) Unvote

func (q *QuoteDB) Unvote(id int, voter string) (bool, error)

Unvote returns true iff there was a vote that was removed, otherwise it return false.

func (*QuoteDB) Upvote

func (q *QuoteDB) Upvote(id int, voter string) (bool, error)

Upvote returns true iff the upvote was applied, if it was not applied it's because the user already has a vote for that quote

func (*QuoteDB) Votes

func (q *QuoteDB) Votes(id int) (up, down int, err error)

Votes retrieves the vote counts for a quote

Jump to

Keyboard shortcuts

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