mysql

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package mysql provides a connection to MySQL database with a connection pool.

Index

Constants

This section is empty.

Variables

ApproxTime is a compare helper for clock skew.

Functions

func ConnectLoop

func ConnectLoop(ctx context.Context, cfg DBConfig, logger *slog.Logger) (db *sql.DB, closeFunc func() error, err error)

ConnectLoop takes config and specified database credentials as input, returning *sql.DB handle for interactions with database. It tries to connect to the database until timeout is exceeded to handle cases when database is not ready yet (e.g. in docker-compose setups).

func NewUOW

func NewUOW(db *sql.DB, logger *slog.Logger) uow.StartUnitOfWork

NewUOW returns an implementation of the interface uow.StartUnitOfWork that will track all repositories.

Types

type AlertStore added in v0.5.0

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

AlertStore implements warnly.AlertStore interface.

func NewAlertStore added in v0.5.0

func NewAlertStore(db ExtendedDB) *AlertStore

NewAlertStore is a constructor of AlertStore.

func (*AlertStore) CreateAlert added in v0.5.0

func (s *AlertStore) CreateAlert(ctx context.Context, alert *warnly.Alert) error

CreateAlert creates a new alert.

func (*AlertStore) DeleteAlert added in v0.5.0

func (s *AlertStore) DeleteAlert(ctx context.Context, alertID int) error

DeleteAlert deletes an alert by ID.

func (*AlertStore) GetAlert added in v0.5.0

func (s *AlertStore) GetAlert(ctx context.Context, alertID int) (*warnly.Alert, error)

GetAlert returns an alert by ID.

func (*AlertStore) ListAlerts added in v0.5.0

func (s *AlertStore) ListAlerts(
	ctx context.Context,
	teamIDs []int,
	projectName string,
	offset,
	limit int,
) ([]warnly.Alert, int, error)

ListAlerts returns a list of alerts for the given criteria.

func (*AlertStore) ListAlertsByProject added in v0.5.0

func (s *AlertStore) ListAlertsByProject(ctx context.Context, projectID int) ([]warnly.Alert, error)

ListAlertsByProject returns alerts for a project.

func (*AlertStore) UpdateAlert added in v0.5.0

func (s *AlertStore) UpdateAlert(ctx context.Context, alert *warnly.Alert) error

UpdateAlert updates an existing alert.

type AssingmentStore

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

AssingmentStore provides issue assignment operations (when an issue is assigned to a user).

func NewAssingmentStore

func NewAssingmentStore(db ExtendedDB) *AssingmentStore

NewAssingmentStore is a constructor of issue assignment database repository.

func (*AssingmentStore) CreateAssingment

func (s *AssingmentStore) CreateAssingment(ctx context.Context, a *warnly.Assignment) error

CreateAssingment creates a new issue assignment in the database (assigns an issue to a user).

func (*AssingmentStore) DeleteAssignment

func (s *AssingmentStore) DeleteAssignment(ctx context.Context, issueID int64) error

DeleteAssignment unassigns an issue from a user.

func (*AssingmentStore) ListAssignedFilters

func (s *AssingmentStore) ListAssignedFilters(
	ctx context.Context,
	criteria *warnly.GetAssignedFiltersCriteria,
) ([]warnly.Filter, error)

func (*AssingmentStore) ListAssingments

func (s *AssingmentStore) ListAssingments(ctx context.Context, issueIDs []int64) ([]*warnly.AssignedUser, error)

ListAssingments lists all assignments for a given issue.

type DBConfig

type DBConfig struct {
	DSN        string        `env:"MYSQL_DSN"   env-default:"username:password@protocol(address)/dbname?param=value" yaml:"dsn"`
	PoolConfig PoolConfig    `yaml:"poolConfig"`
	Timeout    time.Duration `yaml:"timeout"` // timeout for trying to connect to the database
}

DBConfig contains information sufficient for database connection.

type Execer

type Execer interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

Execer is an interface used for executing queries.

type ExtendedDB

type ExtendedDB interface {
	Queryer
	Execer
}

ExtendedDB is a union interface which can query, and exec, with Context.

type IssueStore

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

IssueStore encapsulates issue-related database operations.

func NewIssueStore

func NewIssueStore(db ExtendedDB) *IssueStore

NewIssueStore is a constructor of issue database repository.

func (*IssueStore) GetIssue

func (s *IssueStore) GetIssue(ctx context.Context, criteria warnly.GetIssueCriteria) (*warnly.Issue, error)

GetIssue returns an issue by project identifier and hash obtained from event stacktrace or message.

func (*IssueStore) GetIssueByID

func (s *IssueStore) GetIssueByID(ctx context.Context, issueID int64) (*warnly.Issue, error)

GetIssueByID returns an issue by its unique database identifier.

func (*IssueStore) ListIssues

func (s *IssueStore) ListIssues(ctx context.Context, criteria *warnly.ListIssuesCriteria) ([]warnly.Issue, error)

ListIssues returns a list of issues for given project IDs and time range.

func (*IssueStore) StoreIssue

func (s *IssueStore) StoreIssue(ctx context.Context, i *warnly.Issue) error

StoreIssue stores a new issue in the database.

func (*IssueStore) UpdateLastSeen

func (s *IssueStore) UpdateLastSeen(ctx context.Context, upd *warnly.UpdateLastSeen) error

UpdateLastSeen updates the last seen time of an issue.

type MentionStore

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

MentionStore implements warnly.MentionStore for MySQL.

func NewMentionStore

func NewMentionStore(db ExtendedDB) *MentionStore

NewMentionStore is a constructor of MentionStore.

func (*MentionStore) CreateMentions

func (s *MentionStore) CreateMentions(ctx context.Context, mentions []warnly.Mention) error

CreateMentions creates new mentions in issue discussion (when user was tagged using "@").

func (*MentionStore) DeleteMentions

func (s *MentionStore) DeleteMentions(ctx context.Context, messageID int) error

DeleteMentions deletes all mentions from issue comment.

type MessageStore

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

MessageStore implements warnly.MessageStore for MySQL.

func NewMessageStore

func NewMessageStore(db ExtendedDB) *MessageStore

NewMessageStore is a constructor of MessageStore repository.

func (*MessageStore) CountMessages

func (s *MessageStore) CountMessages(ctx context.Context, issueID int64) (int, error)

CountMessages counts all messages in the issue discussion.

func (*MessageStore) CountMessagesByIDs

func (s *MessageStore) CountMessagesByIDs(ctx context.Context, issueIDs []int64) ([]warnly.MessageCount, error)

CountMessagesByIDs counts all messages in the issue discussion by IDs.

func (*MessageStore) CreateMessage

func (s *MessageStore) CreateMessage(ctx context.Context, m *warnly.Message) error

CreateMessage creates a new message when user comments issue.

func (*MessageStore) DeleteMessage

func (s *MessageStore) DeleteMessage(ctx context.Context, messageID, userID int) error

DeleteMessage deletes a message in the issue discussion.

func (*MessageStore) ListIssueMessages

func (s *MessageStore) ListIssueMessages(ctx context.Context, issueID int64) ([]warnly.IssueMessage, error)

ListIssueMessages is a method that lists all messages (comments) in the issue discussion.

type NotificationStore added in v0.5.0

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

NotificationStore implements warnly.NotificationStore.

func NewNotificationStore added in v0.5.0

func NewNotificationStore(db ExtendedDB) *NotificationStore

NewNotificationStore creates a new NotificationStore.

func (*NotificationStore) AcquireAlertLock added in v0.5.0

func (s *NotificationStore) AcquireAlertLock(ctx context.Context, lock *warnly.AlertLock) (bool, error)

AcquireAlertLock attempts to acquire a lock for processing an alert.

func (*NotificationStore) CleanupExpiredLocks added in v0.5.0

func (s *NotificationStore) CleanupExpiredLocks(ctx context.Context, now time.Time) error

CleanupExpiredLocks removes expired locks.

func (*NotificationStore) CreateAlertNotification added in v0.5.0

func (s *NotificationStore) CreateAlertNotification(ctx context.Context, notification *warnly.AlertNotification) error

CreateAlertNotification creates a new alert notification record.

func (*NotificationStore) CreateNotificationChannel added in v0.5.0

func (s *NotificationStore) CreateNotificationChannel(ctx context.Context, channel *warnly.NotificationChannel) error

CreateNotificationChannel creates a new notification channel.

func (*NotificationStore) CreateWebhookConfig added in v0.5.0

func (s *NotificationStore) CreateWebhookConfig(ctx context.Context, config *warnly.WebhookConfig) error

CreateWebhookConfig creates a new webhook configuration.

func (*NotificationStore) DeleteNotificationChannel added in v0.5.0

func (s *NotificationStore) DeleteNotificationChannel(ctx context.Context, channelID int) error

DeleteNotificationChannel deletes a notification channel.

func (*NotificationStore) GetNotificationChannel added in v0.5.0

func (s *NotificationStore) GetNotificationChannel(ctx context.Context, channelID int) (*warnly.NotificationChannel, error)

GetNotificationChannel returns a notification channel by ID.

func (*NotificationStore) GetWebhookConfig added in v0.5.0

func (s *NotificationStore) GetWebhookConfig(ctx context.Context, channelID int) (*warnly.WebhookConfig, error)

GetWebhookConfig returns a webhook configuration by channel ID.

func (*NotificationStore) ListNotificationChannels added in v0.5.0

func (s *NotificationStore) ListNotificationChannels(ctx context.Context, teamID int) ([]warnly.NotificationChannel, error)

ListNotificationChannels returns all notification channels for a team.

func (*NotificationStore) ListPendingNotifications added in v0.5.0

func (s *NotificationStore) ListPendingNotifications(ctx context.Context, limit int) ([]warnly.AlertNotification, error)

ListPendingNotifications returns all pending notifications.

func (*NotificationStore) ReleaseAlertLock added in v0.5.0

func (s *NotificationStore) ReleaseAlertLock(ctx context.Context, alertID int, instanceID string) error

ReleaseAlertLock releases a lock for an alert.

func (*NotificationStore) UpdateAlertNotification added in v0.5.0

func (s *NotificationStore) UpdateAlertNotification(ctx context.Context, notification *warnly.AlertNotification) error

UpdateAlertNotification updates an alert notification record.

func (*NotificationStore) UpdateNotificationChannel added in v0.5.0

func (s *NotificationStore) UpdateNotificationChannel(ctx context.Context, channel *warnly.NotificationChannel) error

UpdateNotificationChannel updates a notification channel.

func (*NotificationStore) UpdateWebhookConfig added in v0.5.0

func (s *NotificationStore) UpdateWebhookConfig(ctx context.Context, config *warnly.WebhookConfig) error

UpdateWebhookConfig updates a webhook configuration.

type PoolConfig

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

PoolConfig is a db pool configuration.

type ProjectStore

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

ProjectStore implements warnly.ProjectStore for MySQL.

func NewProjectStore

func NewProjectStore(db ExtendedDB) *ProjectStore

NewProjectStore is a constructor of ProjectStore.

func (*ProjectStore) CreateProject

func (s *ProjectStore) CreateProject(ctx context.Context, p *warnly.Project) error

CreateProject is a method that creates a new project.

func (*ProjectStore) DeleteProject

func (s *ProjectStore) DeleteProject(ctx context.Context, projectID int) error

DeleteProject deletes a project by project unique identifier.

func (*ProjectStore) GetOptions

func (s *ProjectStore) GetOptions(ctx context.Context, projectID int, projectKey string) (*warnly.ProjectOptions, error)

GetOptions returns project options by project ID.

func (*ProjectStore) GetProject

func (s *ProjectStore) GetProject(ctx context.Context, projectID int) (*warnly.Project, error)

GetProject returns a project by unique identifier. Returns warnly.ErrProjectNotFound if project does not exist.

func (*ProjectStore) ListProjects

func (s *ProjectStore) ListProjects(
	ctx context.Context,
	teamIDs []int,
	name string,
) ([]warnly.Project, error)

ListProjects returns a list of projects by team unique identifiers.

type Queryer

type Queryer interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Queryer is an interface used for selection queries.

type SQLogger

type SQLogger struct {
	Logger *slog.Logger
}

SQLogger is a logger for mysql.

func (*SQLogger) Print

func (l *SQLogger) Print(v ...any)

Print is a method for logging adapter.

type SessionStore

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

SessionStore encapsulates user session operations.

func NewSessionStore

func NewSessionStore(db ExtendedDB) *SessionStore

NewSessionStore is a constructor of SessionStore.

func (*SessionStore) GetHashedPassword

func (s *SessionStore) GetHashedPassword(ctx context.Context, email string) ([]byte, error)

GetHashedPassword returns a hashed password by email. Returns warnly.ErrNotFound if user with the given email does not exist.

func (*SessionStore) GetHashedPasswordByIdentifier added in v0.2.0

func (s *SessionStore) GetHashedPasswordByIdentifier(ctx context.Context, identifier warnly.UserIdentifier) ([]byte, error)

GetHashedPasswordByIdentifier returns a hashed password by identifier (email or username). Returns warnly.ErrNotFound if user with the given identifier does not exist.

type TeamStore

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

TeamStore provides team operations.

func NewTeamStore

func NewTeamStore(db ExtendedDB) *TeamStore

NewTeamStore is a constructor of TeamStore.

func (*TeamStore) AddUserToTeam added in v0.2.0

func (s *TeamStore) AddUserToTeam(ctx context.Context, createdAt time.Time, userID int64, teamID int) error

AddUserToTeam adds a user to a team.

func (*TeamStore) CreateTeam

func (s *TeamStore) CreateTeam(ctx context.Context, t warnly.Team) error

CreateTeam creates a new team.

func (*TeamStore) ListTeammates

func (s *TeamStore) ListTeammates(ctx context.Context, teamIDs []int) ([]warnly.Teammate, error)

ListTeammates returns a list of teammates for the given team identifiers.

func (*TeamStore) ListTeams

func (s *TeamStore) ListTeams(ctx context.Context, userID int) ([]warnly.Team, error)

ListTeams returns a list of teams by user unique identifier.

type TestInstance

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

TestInstance is a wrapper around the Docker-based database instance.

func MustTestInstance

func MustTestInstance() *TestInstance

MustTestInstance is NewTestInstance, except it prints errors to stderr and calls os.Exit when finished. Callers can call Close or MustClose().

func NewTestInstance

func NewTestInstance() (*TestInstance, error)

NewTestInstance creates a new Docker-based database instance. It also creates an initial database, runs the migrations, and sets that database as a template to be cloned by future tests.

This should not be used outside of testing, but it is exposed in the package so it can be shared with other packages. It should be called and instantiated in TestMain.

func (*TestInstance) Close

func (i *TestInstance) Close() (retErr error)

Close terminates the test database instance, cleaning up any resources.

func (*TestInstance) MustClose

func (i *TestInstance) MustClose() error

MustClose is like Close except it prints the error to stderr and calls os.Exit.

func (*TestInstance) NewDatabase

func (i *TestInstance) NewDatabase(tb testing.TB) (*sql.DB, DBConfig)

NewDatabase creates a new database suitable for use in testing. It returns an established database connection and the configuration.

type UserStore

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

UserStore provides user operations.

func NewUserStore

func NewUserStore(db ExtendedDB) *UserStore

NewUserStore is a constructor of UserStore.

func (*UserStore) CreateUser

func (s *UserStore) CreateUser(ctx context.Context, email, username string, hashedPassword []byte) error

CreateUser creates a user in the database.

func (*UserStore) CreateUserOIDC added in v0.2.0

func (s *UserStore) CreateUserOIDC(ctx context.Context, r *warnly.GetOrCreateUserRequest) (int64, error)

func (*UserStore) GetUser

func (s *UserStore) GetUser(ctx context.Context, email string) (*warnly.User, error)

GetUser returns a user by email. Returns warnly.ErrNotFound if user with the given email does not exist.

func (*UserStore) GetUserByIdentifier added in v0.2.0

func (s *UserStore) GetUserByIdentifier(ctx context.Context, identifier warnly.UserIdentifier) (*warnly.User, error)

GetUserByIdentifier returns a user by identifier (email or username). Returns warnly.ErrNotFound if user with the given identifier does not exist.

Jump to

Keyboard shortcuts

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