database

package
v0.0.0-...-1f70e13 Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionCount

type ActionCount struct {
	Action string `db:"action_formatted" json:"a"`
	Count  int    `db:"count" json:"c"`
}

ActionCount represents a formatted record from the metrics table. Can be marshalled straight to JSON.

type CountRecord

type CountRecord struct {
	GuildCount      int    `db:"guild_count" json:"g"`
	SubscribedCount int    `db:"subscribed_count" json:"s"`
	Date            string `db:"date" json:"d"`
}

CountRecord represents a record in the counts table. Can be marshalled straight to JSON.

type Db

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

Db is a wrapper around sqlx.DB which provides methods for interacting with SLB specific tables.

func NewDb

func NewDb(c config.Config) (Db, error)

NewDb creates a new Db.

func (Db) DeleteSubscribedChannel

func (d Db) DeleteSubscribedChannel(channelId, guildId string) (changed bool, err error)

DeleteSubscribedChannel removes a given channel from the subscribed_channels table.

func (Db) GetSession

func (d Db) GetSession(id string) (exists bool, record SessionRecord, err error)

GetSession gets a session record from the database with the given session id.

func (Db) RemoveSession

func (d Db) RemoveSession(id string) (deleted bool, err error)

RemoveSession remove a session record from the database with the given session id.

func (Db) SetSession

func (d Db) SetSession(id string, accessTokenEncrypted []byte, expiresIn int, refreshTokenEncrypted []byte) (changed bool, err error)

SetSession creates a session record in the database.

func (Db) Stats

func (d Db) Stats() ([]CountRecord, []ActionCount, error)

Stats WIP.

func (Db) SubscribedChannels

func (d Db) SubscribedChannels(guildIds []string) ([]SubscribedChannelRecord, error)

SubscribedChannels returns a slice of SubscribedChannels that exist in the given guild ids.

func (Db) UpdateSubscribedChannel

func (d Db) UpdateSubscribedChannel(channelId, guildId, notificationType, launchMentions string) (changed bool, err error)

UpdateSubscribedChannel sets the notification type and launch mentions for a given channel ID. guildId is required to ensure that the channel exists in that guild.

type SessionRecord

type SessionRecord struct {
	SessionId             string    `db:"session_id"`
	SessionCreationTime   time.Time `db:"session_creation_time"`
	AccessToken           string
	AccessTokenEncrypted  []byte    `db:"access_token_encrypted"`
	AccessTokenExpiresAt  time.Time `db:"access_token_expires_at"`
	RefreshToken          string
	RefreshTokenEncrypted []byte    `db:"refresh_token_encrypted"`
	RefreshTime           time.Time `db:"refresh_time"`
}

SessionRecord represents a record in the sessions table. The 2 non-marshalled-to fields are because we pass this around and we will need store the unencrypted values.

type SubscribedChannelRecord

type SubscribedChannelRecord struct {
	Id               string  `db:"channel_id" json:"id"`
	GuildId          string  `db:"guild_id"`
	Name             string  `db:"channel_name" json:"name"`
	NotificationType string  `db:"notification_type" json:"notification_type"`
	LaunchMentions   *string `db:"launch_mentions" json:"launch_mentions"` // Pointer because it can be NULL in the db.
}

SubscribedChannelRecord represents a record in the subscribed channel table. Can be marshalled straight to JSON, be careful of nil pointers.

Jump to

Keyboard shortcuts

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