Documentation ¶
Overview ¶
Package db handles all database intercations of the server
Index ¶
- Variables
- func All(query r.Term, res interface{}) error
- func BoardCounter(board string) (counter int64, err error)
- func Connect() (err error)
- func CreateIndeces() error
- func CreateTables() error
- func Exec(query r.Term) error
- func FindParentThread(id int64) r.Term
- func FindPost(id int64) r.Term
- func GetAccount(id string) r.Term
- func GetAllBoard() (board *types.Board, err error)
- func GetBoard(board string) (*types.Board, error)
- func GetBoardConfig(id string) r.Term
- func GetImage(id string) r.Term
- func GetLoginHash(id string) (hash []byte, err error)
- func GetMain(id string) r.Term
- func GetPost(id int64) (post types.StandalonePost, err error)
- func GetThread(id int64, lastN int) (*types.Thread, error)
- func IncrementBoardCounter(board string) error
- func InitDB() error
- func LoadDB() (err error)
- func One(query r.Term, res interface{}) error
- func PostCounter() (counter int64, err error)
- func RegisterAccount(ID string, hash []byte) error
- func ReservePostID() (id int64, err error)
- func StreamUpdates(id int64, write chan<- []byte, close <-chan struct{}) ([][]byte, error)
- func ThreadCounter(id int64) (counter int64, err error)
- func UniqueDBName() string
- func ValidateOP(id int64, board string) (valid bool, err error)
- func Write(query r.Term) error
- type ConfigDocument
- type DatabaseHelper
- type Document
Constants ¶
This section is empty.
Variables ¶
var ( // Address of the RethinkDB cluster instance to connect to Address = "localhost:28015" // DBName is the name of the database to use DBName = "meguca" // RSession exports the RethinkDB connection session. Used globally by the // entire server. RSession *r.Session // AllTables are all tables needed for meguca operation AllTables = [...]string{ "main", "threads", "images", "imageTokens", "accounts", "boards", } )
var ( // ErrUserNameTaken denotes a user name the client is trying to register // with is already taken ErrUserNameTaken = errors.New("user name already taken") )
Functions ¶
func BoardCounter ¶
BoardCounter retrieves the history or "progress" counter of a board
func Connect ¶
func Connect() (err error)
Connect establishes a connection to RethinkDB. Address passed separately for easier testing.
func CreateIndeces ¶
func CreateIndeces() error
CreateIndeces create secondary indeces for faster table queries
func CreateTables ¶
func CreateTables() error
CreateTables creates all tables needed for meguca operation
func FindParentThread ¶
FindParentThread finds the parent thread of an arbitrary post number
func GetAccount ¶
GetAccount is a shorthand for retrieving a document from the "accounts" table
func GetAllBoard ¶
GetAllBoard retrieves all threads for the "/all/" meta-board
func GetBoardConfig ¶
GetBoardConfig is a shorthand for retrieving a document from the "boards" table
func GetLoginHash ¶
GetLoginHash retrieves the login hash of the registered user account
func GetPost ¶
func GetPost(id int64) (post types.StandalonePost, err error)
GetPost reads a single post from the database complete with parent board and thread
func IncrementBoardCounter ¶
IncrementBoardCounter increments the progress counter of a board by 1. To be used on post and thread creation
func LoadDB ¶
func LoadDB() (err error)
LoadDB establishes connections to RethinkDB and Redis and bootstraps both databases, if not yet done.
func PostCounter ¶
PostCounter retrieves the current global post count
func RegisterAccount ¶
RegisterAccount writes the ID and password hash of a new user account to the database
func ReservePostID ¶
ReservePostID reserves a post ID number for post and thread creation
func StreamUpdates ¶
StreamUpdates produces a stream of the replication log updates for the specified thread and sends it on read. Close the close channel to stop receiving updates. The intial contents of the log are returned immediately.
func ThreadCounter ¶
ThreadCounter retrieve the history or "progress" counter of a thread
func UniqueDBName ¶
func UniqueDBName() string
UniqueDBName returns a unique datatabase name. Needed so multiple concurent `go test` don't clash in the same database.
func ValidateOP ¶
ValidateOP confirms the specified thread exists on specific board
Types ¶
type ConfigDocument ¶
ConfigDocument holds the global server configurations
type DatabaseHelper ¶
type DatabaseHelper struct {
// contains filtered or unexported fields
}
DatabaseHelper simplifies managing queries, by providing extra utility