Documentation ¶
Overview ¶
Package db handles all core database interactions of the server
Index ¶
- Variables
- func All(query r.Term, res interface{}) error
- func AllocateImage(src, thumb []byte, img types.ImageCommon) error
- func BoardCounter(board string) (counter int64, err error)
- func ClearTables(tables ...string) error
- func Connect() (err error)
- func CreateIndices() error
- func CreateTables() error
- func DeallocateImage(id string) error
- func DeleteThread(id int64) error
- func Exec(query r.Term) error
- func FindImageThumb(hash string) (img types.ImageCommon, err error)
- func FindPost(id int64) r.Term
- func FindThread(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 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 Insert(table string, doc interface{}) error
- func LoadDB() (err error)
- func NewImageToken(SHA1 string) (code int, token string, 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 ThreadCounter(id int64) (counter int64, err error)
- func UseImageToken(id string) (img types.ImageCommon, err error)
- func ValidateOP(id int64, board string) (valid bool, err error)
- func Write(query r.Term) error
- func WriteAll(qs []r.Term) error
- type ConfigDocument
- 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" // IsTest can be overridden to not launch several infinite loops during tests // or check DB version IsTest bool // 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", "posts", "images", "imageTokens", "accounts", "boards", } )
var ( // ErrInvalidToken occurs, when trying to retrieve an image with an // non-existent token. The token might have expired (60 to 119 seconds) or // the client could have provided an invalid token to begin with. ErrInvalidToken = errors.New("invalid image token") )
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 AllocateImage ¶
func AllocateImage(src, thumb []byte, img types.ImageCommon) error
AllocateImage allocates an image's file resources to their respective served directories and write its data to the database
func BoardCounter ¶
BoardCounter retrieves the history or "progress" counter of a board
func ClearTables ¶
ClearTables deletes the contents of specified DB tables. Only used for tests.
func Connect ¶
func Connect() (err error)
Connect establishes a connection to RethinkDB. Address passed separately for easier testing.
func CreateIndices ¶
func CreateIndices() error
CreateIndices creates secondary indices for faster table queries
func CreateTables ¶
func CreateTables() error
CreateTables creates all tables needed for meguca operation
func DeallocateImage ¶
DeallocateImage decrements the image's reference counter. If the counter would become zero, the image entry is immediately deleted along with its file assets.
func DeleteThread ¶
DeleteThread deletes a thread from the database and deallocated any freed up images
func Exec ¶
Exec executes the query and only returns an error, if any. Do not use for write queries.
func FindImageThumb ¶
func FindImageThumb(hash string) (img types.ImageCommon, err error)
FindImageThumb searches for an existing image with the specified hash and returns it, if it exists. Otherwise, returns an empty struct. To ensure the image is not deallocated by another thread/process, the reference counter of the image will be incremented.
func FindThread ¶
FindThread is a shorthand for retrieving a document from the "threads" table
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 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
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 NewImageToken ¶
NewImageToken inserts a new expiring image token document into the DB and returns it's ID
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 ThreadCounter ¶
ThreadCounter retrieves the post counter of a thread to get a rough estimate of the thread's progress
func UseImageToken ¶
func UseImageToken(id string) (img types.ImageCommon, err error)
UseImageToken deletes a document from the "imageTokens" table and uses and returns the Image document from the "images" table, the token was created for. If no token exists, returns ErrInvalidToken.
func ValidateOP ¶
ValidateOP confirms the specified thread exists on specific board
Types ¶
type ConfigDocument ¶
ConfigDocument holds the global server configurations