db

package
v1.7.6-0...-a17e0fe Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package db handles all database intercations of the server

Index

Constants

This section is empty.

Variables

View Source
var AllTables = [...]string{"main", "threads", "posts"}

AllTables are all tables needed for meguca operation

View Source
var RSession *r.Session

RSession exports the RethinkDB connection session. Used globally by the entire server.

Functions

func BoardCounter

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

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

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 DB

func DB() func(r.Term) DatabaseHelper

DB returns a function that creates a new DatabaseHelper. Used to simplify database queries. Simply DB()(${query}).${method}() Example: err := DB()(r.Table("posts").Get(1)).One(&Post)

func LoadDB

func LoadDB() (err error)

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

func PostCounter

func PostCounter() (counter uint64, err error)

PostCounter retrieves the current post counter number

func ThreadCounter

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

ThreadCounter retrieve the history or "progress" counter of a thread

func ValidateOP

func ValidateOP(id uint64, 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 (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(board string, 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 types.Board, err error)

GetBoard retrieves all OPs of a single board

func (*Reader) GetPost

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

GetPost reads a single post from the database

func (*Reader) GetThread

func (rd *Reader) GetThread(id uint64, lastN int) (
	types.ThreadContainer,
	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