db

package
v2.0.0-alpha+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package db handles all database intercations of the server

Index

Constants

This section is empty.

Variables

View Source
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

func BoardCounter(board string) (counter int64, err error)

BoardCounter retrieves the history or "progress" counter of a board

func Connect

func Connect(addr string) (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 GetImage

func GetImage(id string) r.Term

GetImage is a shorthand for retrieving a document from the "images" table

func GetMain

func GetMain(id string) r.Term

GetMain is a shorthand for retrieving a document from the "main" table

func InitDB

func InitDB(dbName string) error

InitDB initialize a rethinkDB database

func LoadDB

func LoadDB() (err error)

LoadDB establishes connections to RethinkDB and Redis and bootstraps both databases, if not yet done.

func ParentThread

func ParentThread(id int64) (op int64, err error)

ParentThread determines the parent thread of a post. Returns 0, if post not found.

func PostCounter

func PostCounter() (counter int64, err error)

PostCounter retrieves the current global post count

func StreamUpdates

func StreamUpdates(
	id int64,
	write chan<- []byte,
	closer *util.AtomicCloser,
) ([][]byte, error)

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

func ThreadCounter(id int64) (counter int64, err error)

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

func ValidateOP(id int64, board string) (valid bool, err error)

ValidateOP confirms the specified thread exists on specific board

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 NewReader

func NewReader(ident auth.Ident) *Reader

NewReader constructs a new Reader instance

func (*Reader) GetAllBoard

func (rd *Reader) GetAllBoard() (board *types.Board, err error)

GetAllBoard retrieves all threads the client has access to for the "/all/" meta-board

func (*Reader) GetBoard

func (rd *Reader) GetBoard(board string) (out *types.Board, err error)

GetBoard retrieves all OPs of a single board

func (*Reader) GetPost

func (rd *Reader) GetPost(id, op int64) (post types.Post, err error)

GetPost reads a single post from the database

func (*Reader) GetThread

func (rd *Reader) GetThread(id int64, lastN int) (*types.Thread, error)

GetThread retrieves thread JSON from the database

Jump to

Keyboard shortcuts

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