Documentation ¶
Overview ¶
Package db handles all core database interactions of the server
Index ¶
- Constants
- Variables
- func AllBoardCounter() (uint64, error)
- func AllocateImage(src, thumb []byte, img common.ImageCommon) (err error)
- func Ban(board, reason, by string, expires time.Time, ids ...uint64) (ips map[string]uint64, err error)
- func BeginTx() (tx *sql.Tx, err error)
- func BoardCounter(board string) (uint64, error)
- func CanCreatePost(ip string) bool
- func CanCreateThread(ip string) bool
- func ChangePassword(account string, hash []byte) error
- func DeleteBoard(board string) error
- func DeleteImageToken(token string) (err error)
- func DeletePost(id uint64, by string) error
- func EndTx(tx *sql.Tx, err *error)
- func GetAllBoardCatalog() (common.Board, error)
- func GetAllThreadsIDs() ([]uint64, error)
- func GetBanInfo(ip, board string) (b auth.BanRecord, err error)
- func GetBans(tx *sql.Tx, boards []string) (bans auth.BanRecords, err error)
- func GetBoardCatalog(board string) (common.Board, error)
- func GetBoardConfig(tx *sql.Tx, board string) (config.BoardConfig, error)
- func GetIP(id uint64) (string, error)
- func GetImage(SHA1 string) (common.ImageCommon, error)
- func GetModLog(boards []string) (log auth.ModLogRecords, err error)
- func GetOwnedBoards(account string) (boards []string, err error)
- func GetPassword(id string) (hash []byte, err error)
- func GetPost(id uint64) (p common.StandalonePost, err error)
- func GetPostBoard(id uint64) (board string, err error)
- func GetPostOP(id uint64) (op uint64, err error)
- func GetPostParenthood(id uint64) (board string, op uint64, err error)
- func GetSameIPPosts(id uint64, board string) (posts []common.StandalonePost, err error)
- func GetSession(board, token string) (ss *auth.Session, err error)
- func GetStaff(tx *sql.Tx, boards []string) (staff auth.Staff, err error)
- func GetThread(id uint64, lastN int) (t common.Thread, err error)
- func GetThreadIDs(board string) ([]uint64, error)
- func InsertFiles(tx *sql.Tx, p Post) (err error)
- func InsertPost(tx *sql.Tx, p Post) (err error)
- func InsertThread(tx *sql.Tx, p Post, subject string) (err error)
- func IsConflictError(err error) booldeprecated
- func IsForeignKeyViolationError(err error) bool
- func IsUniqueViolationError(err error) bool
- func Listen(event string) (*pq.Listener, error)
- func LogOut(account, token string) error
- func LogOutAll(account string) error
- func NewImageToken(SHA1 string) (token string, err error)
- func NewPostID(tx *sql.Tx) (id uint64, err error)
- func NewPostToken(ip string) (token string, err error)
- func PostCounter() (uint64, error)
- func RefreshBanCache() (err error)
- func RegisterAccount(ID string, hash []byte) error
- func RollbackOnError(tx *sql.Tx, err *error)
- func SetAccountSettings(userID string, as auth.AccountSettings) (err error)
- func SetBoardState(tx *sql.Tx, state BoardState, by string) (err error)
- func SetReadOnly(tx *sql.Tx) error
- func SetRepeatableRead(tx *sql.Tx) (err error)
- func SetServerConfig(c config.ServerConfig) error
- func SetThreadSticky(id uint64, sticky bool) error
- func StartDB() (err error)
- func StartTransaction() (*sql.Tx, error)deprecated
- func ThreadCounter(id uint64) (uint64, error)
- func Unban(board string, id uint64, by string) error
- func UpdateBoard(tx *sql.Tx, c config.BoardConfig, by string) (err error)
- func UpsertIdolPreview(idolId string, imageId string) (err error)
- func UseImageToken(tx *sql.Tx, token string) (img common.ImageCommon, err error)
- func UsePostToken(token string) (err error)
- func ValidateOP(id uint64, board string) (valid bool, err error)
- func WriteBans(tx *sql.Tx, board string, bans auth.BanRecords) (err error)
- func WriteBoard(tx *sql.Tx, c config.BoardConfig) (err error)
- func WriteImage(tx *sql.Tx, i common.ImageCommon) error
- func WriteLoginSession(account, token string) error
- func WriteStaff(tx *sql.Tx, board string, staff auth.Staff) (err error)
- type BoardState
- type Post
- type PostStats
- type Thread
Constants ¶
const (
// TestConnArgs contains ConnArgs used for tests
TestConnArgs = `user=meguca password=meguca dbname=meguca_test sslmode=disable`
)
Variables ¶
var ( // ConnArgs specifies the PostgreSQL connection arguments ConnArgs string // IsTest can be overridden to not launch several infinite loops // during tests IsTest bool )
var ( // ErrInvalidToken occurs, when trying to retrieve post or image with // an non-existent token. The token might have expired or the client // could have provided an invalid token to begin with. ErrInvalidToken = errors.New("invalid token") // Occurs when client tries to retrieve too much tokens. ErrTokenForbidden = errors.New("token forbidden") )
var (
ErrUserNameTaken = errors.New("user name already taken")
)
Functions ¶
func AllBoardCounter ¶
AllBoardCounter retrieves the progress counter of the /all/ board
func AllocateImage ¶
func AllocateImage(src, thumb []byte, img common.ImageCommon) (err error)
AllocateImage allocates an image's file resources to their respective served directories and write its data to the database.
func Ban ¶
func Ban(board, reason, by string, expires time.Time, ids ...uint64) ( ips map[string]uint64, err error, )
Ban IPs from accessing a specific board. Need to target posts. Returns all banned IPs.
func BeginTx ¶
Initiate a new DB transaction. It is the responsibility of the caller to commit or rollback the transaction.
func BoardCounter ¶
BoardCounter retrieves the progress counter of a board
func CanCreatePost ¶
func CanCreateThread ¶
func ChangePassword ¶
ChangePassword changes an existing user's login password
func DeleteBoard ¶
DeleteBoard deletes a board and all of its contained threads and posts.
func DeleteImageToken ¶
func DeletePost ¶
func GetAllBoardCatalog ¶
GetAllBoardCatalog retrieves all OPs for the "/all/" meta-board.
func GetAllThreadsIDs ¶
Retrieves all threads IDs in bump order with stickies first.
func GetBanInfo ¶
GetBanInfo retrieves information about a specific ban
func GetBans ¶
Get bans for the specified boards. TODO(Kagami): Get from cache? TODO(Kagami): Pagination.
func GetBoardCatalog ¶
GetBoardCatalog retrieves all OPs of a single board.
func GetBoardConfig ¶
func GetIP ¶
GetIP returns an IP of the poster that created a post. Posts older than 7 days will not have this information.
func GetImage ¶
func GetImage(SHA1 string) (common.ImageCommon, error)
GetImage retrieves a thumbnailed image record from the DB.
func GetModLog ¶
func GetModLog(boards []string) (log auth.ModLogRecords, err error)
Retrieve moderation log for the specified boards. TODO(Kagami): Pagination.
func GetOwnedBoards ¶
GetOwnedBoards returns boards the account holder owns
func GetPassword ¶
GetPassword retrieves the login password hash of the registered user account
func GetPost ¶
func GetPost(id uint64) (p common.StandalonePost, err error)
GetPost reads a single post from the database.
func GetPostBoard ¶
GetPostBoard retrieves the board of a post by ID
func GetPostParenthood ¶
Retrieve the board and OP of a post
func GetSameIPPosts ¶
func GetSameIPPosts(id uint64, board string) ( posts []common.StandalonePost, err error, )
GetSameIPPosts returns posts with the same IP and on the same board as the target post
func GetSession ¶
Get user's session by token.
func GetStaff ¶
Retrieve staff positions for the specificied boards. TODO(Kagami): Get from cache? TODO(Kagami): Pagination.
func GetThreadIDs ¶
Retrieves threads IDs on the board.
func InsertFiles ¶
Write post files in current transaction.
func InsertPost ¶
InsertPost inserts a post into an existing thread.
func InsertThread ¶
InsertThread inserts a new thread into the database.
func IsConflictError
deprecated
func IsUniqueViolationError ¶
func NewImageToken ¶
NewImageToken inserts a new image allocation token into the DB and returns it's ID.
func NewPostToken ¶
func PostCounter ¶
PostCounter retrieves the current post counter
func RefreshBanCache ¶
func RefreshBanCache() (err error)
RefreshBanCache loads up to date bans from the database and caches them in memory
func RegisterAccount ¶
RegisterAccount writes the ID and password hash of a new user account to the database
func RollbackOnError ¶
RollbackOnError on error undoes the transaction on error. Deprecated: move to EndTx instead.
func SetAccountSettings ¶
func SetAccountSettings(userID string, as auth.AccountSettings) (err error)
func SetBoardState ¶
func SetBoardState(tx *sql.Tx, state BoardState, by string) (err error)
func SetReadOnly ¶
func SetRepeatableRead ¶
func SetServerConfig ¶
func SetServerConfig(c config.ServerConfig) error
func SetThreadSticky ¶
Set the sticky field on a thread
func StartTransaction
deprecated
func ThreadCounter ¶
ThreadCounter retrieves the progress counter of a thread
func UpdateBoard ¶
func UpsertIdolPreview ¶
Update or insert preview for the idol.
func UseImageToken ¶
UseImageToken deletes an image allocation token and returns the matching processed image. If no token exists, returns ErrInvalidToken.
func UsePostToken ¶
func ValidateOP ¶
ValidateOP confirms the specified thread exists on specific board
func WriteBoard ¶
func WriteBoard(tx *sql.Tx, c config.BoardConfig) (err error)
func WriteImage ¶
func WriteImage(tx *sql.Tx, i common.ImageCommon) error
WriteImage writes a processed image record to the DB.
func WriteLoginSession ¶
WriteLoginSession writes a new user login session to the DB
Types ¶
type BoardState ¶
type BoardState struct { Settings config.BoardConfig `json:"settings"` Staff auth.Staff `json:"staff"` Bans auth.BanRecords `json:"bans"` }
func GetBoardState ¶
func GetBoardState(tx *sql.Tx, board string) (state BoardState, err error)
type Post ¶
type Post struct { common.StandalonePost Password []byte IP string }
Post is for writing new posts to a database. It contains the Password field, which is never exposed publically through Post.
type PostStats ¶
PostStats contains post open status, body and creation time.
func GetRecentPosts ¶
GetRecentPosts retrieves recent posts created in the thread.