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 AllocateSmileImage(src []byte, smile common.SmileCommon) (err error)
- func AssertNotReacted(ss *auth.Session, postID uint64, smileName string) (r bool)
- 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 DeletePostReaction(postID uint64, smileName string) (err error)
- func DeleteSmile(board string, smileName string) error
- func DeleteUserReaction(ss *auth.Session, reactionID uint64) (err 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 GetBoardSmiles(board string) (smiles []common.SmileCommon, err error)
- func GetBoardWithGlobalSmiles(board string) []common.SmileCommon
- func GetIP(id uint64) (string, error)
- func GetImage(SHA1 string) (common.ImageCommon, error)
- func GetModLog(boards []string) (log auth.ModLogRecords, err error)
- func GetNews() (news []common.NewsEntry, 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 GetPostReactCount(id uint64, smileName string) (count uint64)
- func GetPostReacts(id uint64) (reacts common.Reacts, err error)
- func GetSameIPPosts(id uint64, board string) (posts []common.StandalonePost, err error)
- func GetSession(board, token string) (ss *auth.Session, err error)
- func GetSmile(smileName string, board string) (s common.SmileCommon, 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 GetThreadReacts(id uint64) (reacts common.Reacts, err error)
- func GetThreadUserReacts(ss *auth.Session, threadID uint64) (reacts common.Reacts, err error)
- func GetUniqueID(id uint64) (string, error)
- func InsertFiles(tx *sql.Tx, p Post) (err error)
- func InsertPost(tx *sql.Tx, p Post) (err error)
- func InsertPostReaction(postID uint64, smileID uint64) (reactionID uint64, err error)
- func InsertThread(tx *sql.Tx, p Post, subject string) (err error)
- func InsertUserReaction(ss *auth.Session, reactionID uint64) (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 RenameSmile(board string, smileName string, originalName string) 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 UpdateReactionCount(postID uint64, smileName string, count uint64) (reactionID uint64, err error)
- func UseImageToken(tx *sql.Tx, token string) (img common.ImageCommon, err error)
- func UsePostToken(token string) (err error)
- func ValidSmileName(smileName string, board string) (valid bool, 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 WriteSmileImage(tx *sql.Tx, s common.SmileCommon) error
- func WriteStaff(tx *sql.Tx, board string, staff auth.Staff) (err error)
- type AccountSettings
- type BoardState
- type NullString
- type Post
- type PostStats
- type String
- type Thread
Constants ¶
const (
// TestConnArgs contains ConnArgs used for tests
TestConnArgs = `user=meguca password=meguca dbname=meguca_test sslmode=disable`
)
Variables ¶
var ( ErrUserNameTaken = errors.New("User name already taken") ErrContrast = errors.New("Color must be distinguishable in both themes. Increase contrast.") )
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") )
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 AllocateSmileImage ¶
func AllocateSmileImage(src []byte, smile common.SmileCommon) (err error)
AllocateSmileImage allocates an image's file resources to their respective served directories and write its data to the database.
func AssertNotReacted ¶
AssertNotReacted ensures that user with following ip or accountID haven't reacted to post with following smileName
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 DeletePostReaction ¶
DeletePostReaction deletes item from post_reacts column
func DeleteSmile ¶
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 ¶
GetBans gets 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 GetBoardSmiles ¶
func GetBoardSmiles(board string) (smiles []common.SmileCommon, err error)
GetBoardSmiles returns board's smiles.
func GetBoardWithGlobalSmiles ¶
func GetBoardWithGlobalSmiles(board string) []common.SmileCommon
GetBoardWithGlobalSmiles returns concatenated list of board and global smiles. Global should be last, as board is prioritized.
func GetIP ¶
GetIP returns an IP of the poster that created a post. Posts older than 30 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)
GetModLog retrieves 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 GetPostReactCount ¶
GetPostReactCount reads a single post reaction from the database.
func GetPostReacts ¶
GetPostReacts reads a list of post reactions
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 ¶
GetStaff retrieves staff positions for the specificied boards. TODO(Kagami): Get from cache? TODO(Kagami): Pagination.
func GetThreadIDs ¶
Retrieves threads IDs on the board.
func GetThreadReacts ¶
GetThreadReacts reads a list of thread reactions
func GetThreadUserReacts ¶
GetThreadUserReacts reads a list of thread reactions
func GetUniqueID ¶
GetUniqueID returns post's unique identified. Posts older than 30 days will not have this information
func InsertFiles ¶
InsertFiles write post files in current transaction.
func InsertPost ¶
InsertPost inserts a post into an existing thread.
func InsertPostReaction ¶
InsertPostReaction inserts a post's reaction with relation to post.
func InsertThread ¶
InsertThread inserts a new thread into the database.
func InsertUserReaction ¶
InsertUserReaction inserts a post's reaction with relation to post.
func IsConflictError
deprecated
func IsUniqueViolationError ¶
func NewImageToken ¶
NewImageToken inserts a new image allocation token into the DB and returns it's ID.
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)
SetBoardState sets board states...
func SetReadOnly ¶
func SetRepeatableRead ¶
func SetServerConfig ¶
func SetServerConfig(c config.ServerConfig) error
func SetThreadSticky ¶
SetThreadSticky sets the sticky field on a thread
func StartTransaction
deprecated
func ThreadCounter ¶
ThreadCounter retrieves the progress counter of a thread
func UpdateBoard ¶
func UpdateReactionCount ¶
func UpdateReactionCount(postID uint64, smileName string, count uint64) (reactionID uint64, err error)
UpdateReactionCount updates count of post_reacts column
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
func WriteSmileImage ¶
func WriteSmileImage(tx *sql.Tx, s common.SmileCommon) error
Types ¶
type AccountSettings ¶
type AccountSettings struct {
Color string `json:"color,omitempty"`
}
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)
GetBoardState gets board states...
type NullString ¶
type NullString sql.NullString
type Post ¶
type Post struct { common.StandalonePost Password []byte IP string UniqueID 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.
type String ¶
type String sql.NullString