Documentation ¶
Overview ¶
Package db handles all database intercations of the server
Index ¶
- Variables
- func BoardCounter(board string) (counter int64, err error)
- func Connect(addr string) (err error)
- func CreateIndeces() error
- func CreateTables() error
- func GetImage(id string) r.Term
- func GetMain(id string) r.Term
- func InitDB(dbName string) error
- func LoadDB() (err error)
- func ParentThread(id int64) (op int64, err error)
- func PostCounter() (counter int64, err error)
- func StreamUpdates(id int64, write chan<- []byte, closer *util.AtomicCloser) ([][]byte, error)
- func ThreadCounter(id int64) (counter int64, err error)
- func UniqueDBName() string
- func ValidateOP(id int64, board string) (valid bool, err error)
- type DatabaseHelper
- type Document
- type Reader
Constants ¶
This section is empty.
Variables ¶
var ( // 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"} )
Functions ¶
func BoardCounter ¶
BoardCounter retrieves the history or "progress" counter of a board
func Connect ¶
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 LoadDB ¶
func LoadDB() (err error)
LoadDB establishes connections to RethinkDB and Redis and bootstraps both databases, if not yet done.
func ParentThread ¶
ParentThread determines the parent thread of a post. Returns 0, if post not found.
func PostCounter ¶
PostCounter retrieves the current global post count
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.
Types ¶
type DatabaseHelper ¶
type DatabaseHelper struct {
// contains filtered or unexported fields
}
DatabaseHelper simplifies managing queries, by providing extra utility
func DB ¶
func DB(query r.Term) DatabaseHelper
DB creates a new DatabaseHelper. Used to simplify database queries. Example: err := DB(r.Table("posts").Get(1)).One(&Post)
func (DatabaseHelper) All ¶
func (d DatabaseHelper) All(res interface{}) error
All writes all responses into target pointer to slice or returns error
func (DatabaseHelper) Exec ¶
func (d DatabaseHelper) Exec() error
Exec excutes the inner query and only returns an error, if any
func (DatabaseHelper) One ¶
func (d DatabaseHelper) One(res interface{}) error
One writes the query result into the target pointer or throws an error
type Document ¶
type Document struct {
ID string `gorethink:"id"`
}
Document is a eneric RethinkDB Document. For DRY-ness.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads on formats thread, post and board structs
func (*Reader) GetAllBoard ¶
GetAllBoard retrieves all threads the client has access to for the "/all/" meta-board