db

package
v6.0.0-...-7081d96 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2016 License: AGPL-3.0, AGPL-3.0-or-later Imports: 11 Imported by: 0

Documentation

Overview

Package db handles all database intercations of the server

Index

Constants

This section is empty.

Variables

View Source
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",
	}
)
View Source
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 All

func All(query r.Term, res interface{}) error

All writes all responses into target pointer to slice or returns error

func BoardCounter

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

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 Exec

func Exec(query r.Term) error

Exec excutes the query and only returns an error, if any. Do not use for write queries.

func FindParentThread

func FindParentThread(id int64) r.Term

FindParentThread finds the parent thread of an arbitrary post number

func FindPost

func FindPost(id int64) r.Term

FindPost finds a post only by ID number

func GetAccount

func GetAccount(id string) r.Term

GetAccount is a shorthand for retrieving a document from the "accounts" table

func GetAllBoard

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

GetAllBoard retrieves all threads for the "/all/" meta-board

func GetBoard

func GetBoard(board string) (*types.Board, error)

GetBoard retrieves all OPs of a single board

func GetBoardConfig

func GetBoardConfig(id string) r.Term

GetBoardConfig is a shorthand for retrieving a document from the "boards" table

func GetImage

func GetImage(id string) r.Term

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

func GetLoginHash

func GetLoginHash(id string) (hash []byte, err error)

GetLoginHash retrieves the login hash of the registered user account

func GetMain

func GetMain(id string) r.Term

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

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 GetThread

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

GetThread retrieves public thread data from the database

func IncrementBoardCounter

func IncrementBoardCounter(board string) error

IncrementBoardCounter increments the progress counter of a board by 1. To be used on post and thread creation

func InitDB

func InitDB() 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 One

func One(query r.Term, res interface{}) error

One writes the query result into the target pointer or throws an error

func PostCounter

func PostCounter() (counter int64, err error)

PostCounter retrieves the current global post count

func RegisterAccount

func RegisterAccount(ID string, hash []byte) error

RegisterAccount writes the ID and password hash of a new user account to the database

func ReservePostID

func ReservePostID() (id int64, err error)

ReservePostID reserves a post ID number for post and thread creation

func StreamUpdates

func StreamUpdates(id int64, write chan<- []byte, close <-chan struct{}) (
	[][]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

func Write

func Write(query r.Term) error

Write executes the inner query and returns an error, if any. Only use this function for write queries

Types

type ConfigDocument

type ConfigDocument struct {
	Document
	config.Configs
}

ConfigDocument holds the global server configurations

type DatabaseHelper

type DatabaseHelper struct {
	// contains filtered or unexported fields
}

DatabaseHelper simplifies managing queries, by providing extra utility

type Document

type Document struct {
	ID string `gorethink:"id"`
}

Document is a eneric RethinkDB Document. For DRY-ness.

Jump to

Keyboard shortcuts

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