db

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: None detected not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func BanUser

func BanUser(db *pgxpool.Pool, ownerID, banishedID, reason string, duration int) error

func Connect

func Connect() (*pgxpool.Pool, error)

func CreateChannel

func CreateChannel(db *pgxpool.Pool, name string, description string) error

func FetchBanRecords

func FetchBanRecords(db *pgxpool.Pool, limit, offset int) ([]models.BanRecord, bool, error)

func FetchChannels

func FetchChannels(db *pgxpool.Pool) ([]models.Channel, error)

FetchChannels retrieves all channels from the database's `channels` table. For each channel, if the `description` column is NULL, the Channel.Description field will be set to nil in the returned slice. Otherwise, it contains the description as a pointer to a string. It returns:

  1. A slice of Channel models
  2. An error, if any

func FetchMessageCountByChannel

func FetchMessageCountByChannel(db *pgxpool.Pool) ([]api.ChannelMessageCount, error)

FetchMessageCountByChannel returns the total number of chat messages per channel. It queries the `chat_messages` table, grouping by the `channel` column to produce a list of channels and their respective message counts. It returns:

  1. A slice of ChannelMessageCount, where each item contains a channel name and a message count
  2. An error, if the query or row scanning fails

func FetchMessages

func FetchMessages(db *pgxpool.Pool, userID string, channels []string, keyword string, limit, offset int) ([]models.ChatMessage, bool, error)

FetchMessages retrieves cchat messages from the database. Filters can be applied via userID, channels, and keywords. Pagination is controlled by 'limit' and 'offset'. It returns: 1) A slice of ChatMessage objects. 2) A boolean indicating whether there are more results beyond this page. 3) An error, if any occurred.

func FetchSessionActivity

func FetchSessionActivity(db *pgxpool.Pool, userID string) ([]models.SessionActivity, error)

func FetchUsers

func FetchUsers(db *pgxpool.Pool, username string) ([]models.User, error)

func FlushPrivateMessages

func FlushPrivateMessages(db *pgxpool.Pool, messages []models.PrivateChatMessage) error

FlushPrivateMessages inserts a batch of private messages into the database.

func GetRateLimiterByID

func GetRateLimiterByID(db *pgxpool.Pool, rateLimiterID int) (models.RateLimiter, error)

func IsUserBanned

func IsUserBanned(db *pgxpool.Pool, banishedID string) (bool, error)

func MoveChannelBefore

func MoveChannelBefore(db *pgxpool.Pool, movedID int, beforeID *int) error

MoveChannelBefore reorders a channel to appear before another channel. If beforeID is nil, it moves the channel to the end.

func PardonUser

func PardonUser(db *pgxpool.Pool, banishedID int) error

func RecordUserSession

func RecordUserSession(db *pgxpool.Pool, userID string, start, end time.Time) error

func RemoveChannelByID

func RemoveChannelByID(db *pgxpool.Pool, channelID int, purgeMessages bool) error

func RemoveMessage

func RemoveMessage(db *pgxpool.Pool, messageID int) (bool, error)

RemoveMessage is currently unused. TODO: remove?

func RemoveMessages

func RemoveMessages(db *pgxpool.Pool, messageIDs []int) (int64, []int, error)

RemoveMessages deletes multiple chat messages by their IDs. Before deleting, it fetches each message's cacheID. It returns:

  1. rowsDeleted: the number of rows actually deleted.
  2. cacheIDs: a list of cacheIDs associated with the deleted messages.
  3. An error, if any.

func UpdateChannel

func UpdateChannel(db *pgxpool.Pool, ID int, name *string, description *string) error

func UpdateRateLimiter

func UpdateRateLimiter(db *pgxpool.Pool, rateLimiterID, messageLimit, windowSeconds int) error

Types

type ServerIdentity

type ServerIdentity struct {
	ID   string
	Name string
}

func RegisterOrLoadServer

func RegisterOrLoadServer(db *pgxpool.Pool) ServerIdentity

Jump to

Keyboard shortcuts

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