mysql

package
v0.0.0-...-9518a5e Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package mysql provides an interface for writing to a MySQL instance.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilInputProvided indicates nil input was provided in an unacceptable context.
	ErrNilInputProvided = errors.New("nil input provided")

	// ErrNilTransactionProvided indicates nil transaction was provided in an unacceptable context.
	ErrNilTransactionProvided = errors.New("empty input provided")

	// ErrEmptyInputProvided indicates empty input was provided in an unacceptable context.
	ErrEmptyInputProvided = errors.New("empty input provided")

	// ErrInvalidIDProvided indicates a required ID was passed in as zero.
	ErrInvalidIDProvided = errors.New("required ID provided is zero")
)

Functions

func ProvideDatabaseClient

func ProvideDatabaseClient(
	ctx context.Context,
	logger logging.Logger,
	cfg *dbconfig.Config,
	shouldCreateTestUser bool,
) (database.DataManager, error)

ProvideDatabaseClient provides a new DataManager client.

Types

type SQLQuerier

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

SQLQuerier is the primary database querying client. All tracing/logging/query execution happens here. Query building generally happens elsewhere.

func (*SQLQuerier) AddUserToAccount

func (q *SQLQuerier) AddUserToAccount(ctx context.Context, input *types.AddUserToAccountInput) error

AddUserToAccount does a thing.

func (*SQLQuerier) ArchiveAPIClient

func (q *SQLQuerier) ArchiveAPIClient(ctx context.Context, clientID, userID string) error

ArchiveAPIClient archives an API client.

func (*SQLQuerier) ArchiveAccount

func (q *SQLQuerier) ArchiveAccount(ctx context.Context, accountID, userID string) error

ArchiveAccount archives an account from the database by its ID.

func (*SQLQuerier) ArchiveItem

func (q *SQLQuerier) ArchiveItem(ctx context.Context, itemID, accountID string) error

ArchiveItem archives an item from the database by its ID.

func (*SQLQuerier) ArchiveUser

func (q *SQLQuerier) ArchiveUser(ctx context.Context, userID string) error

ArchiveUser archives a user.

func (*SQLQuerier) ArchiveWebhook

func (q *SQLQuerier) ArchiveWebhook(ctx context.Context, webhookID, accountID string) error

ArchiveWebhook archives a webhook from the database.

func (*SQLQuerier) BuildSessionContextDataForUser

func (q *SQLQuerier) BuildSessionContextDataForUser(ctx context.Context, userID string) (*types.SessionContextData, error)

BuildSessionContextDataForUser queries the database for the memberships of a user and constructs a SessionContextData struct from the results.

func (*SQLQuerier) CreateAPIClient

func (q *SQLQuerier) CreateAPIClient(ctx context.Context, input *types.APIClientCreationInput) (*types.APIClient, error)

CreateAPIClient creates an API client.

func (*SQLQuerier) CreateAccount

func (q *SQLQuerier) CreateAccount(ctx context.Context, input *types.AccountCreationInput) (*types.Account, error)

CreateAccount creates an account in the database.

func (*SQLQuerier) CreateItem

func (q *SQLQuerier) CreateItem(ctx context.Context, input *types.ItemDatabaseCreationInput) (*types.Item, error)

CreateItem creates an item in the database.

func (*SQLQuerier) CreateUser

func (q *SQLQuerier) CreateUser(ctx context.Context, input *types.UserDataStoreCreationInput) (*types.User, error)

CreateUser creates a user.

func (*SQLQuerier) CreateWebhook

func (q *SQLQuerier) CreateWebhook(ctx context.Context, input *types.WebhookDatabaseCreationInput) (*types.Webhook, error)

CreateWebhook creates a webhook in a database.

func (*SQLQuerier) GetAPIClientByClientID

func (q *SQLQuerier) GetAPIClientByClientID(ctx context.Context, clientID string) (*types.APIClient, error)

GetAPIClientByClientID gets an API client from the database.

func (*SQLQuerier) GetAPIClientByDatabaseID

func (q *SQLQuerier) GetAPIClientByDatabaseID(ctx context.Context, clientID, userID string) (*types.APIClient, error)

GetAPIClientByDatabaseID gets an API client from the database.

func (*SQLQuerier) GetAPIClients

func (q *SQLQuerier) GetAPIClients(ctx context.Context, userID string, filter *types.QueryFilter) (x *types.APIClientList, err error)

GetAPIClients gets a list of API clients.

func (*SQLQuerier) GetAccount

func (q *SQLQuerier) GetAccount(ctx context.Context, accountID, userID string) (*types.Account, error)

GetAccount fetches an account from the database.

func (*SQLQuerier) GetAccounts

func (q *SQLQuerier) GetAccounts(ctx context.Context, userID string, filter *types.QueryFilter) (x *types.AccountList, err error)

GetAccounts fetches a list of accounts from the database that meet a particular filter.

func (*SQLQuerier) GetAccountsForAdmin

func (q *SQLQuerier) GetAccountsForAdmin(ctx context.Context, filter *types.QueryFilter) (x *types.AccountList, err error)

GetAccountsForAdmin fetches a list of accounts from the database that meet a particular filter for all users.

func (*SQLQuerier) GetAllAccountsCount

func (q *SQLQuerier) GetAllAccountsCount(ctx context.Context) (uint64, error)

GetAllAccountsCount fetches the count of accounts from the database that meet a particular filter.

func (*SQLQuerier) GetAllUsersCount

func (q *SQLQuerier) GetAllUsersCount(ctx context.Context) (uint64, error)

GetAllUsersCount fetches a count of users from the database that meet a particular filter.

func (*SQLQuerier) GetAllWebhooksCount

func (q *SQLQuerier) GetAllWebhooksCount(ctx context.Context) (uint64, error)

GetAllWebhooksCount fetches the count of webhooks from the database that meet a particular filter.

func (*SQLQuerier) GetDefaultAccountIDForUser

func (q *SQLQuerier) GetDefaultAccountIDForUser(ctx context.Context, userID string) (string, error)

GetDefaultAccountIDForUser retrieves the default account ID for a user.

func (*SQLQuerier) GetItem

func (q *SQLQuerier) GetItem(ctx context.Context, itemID, accountID string) (*types.Item, error)

GetItem fetches an item from the database.

func (*SQLQuerier) GetItems

func (q *SQLQuerier) GetItems(ctx context.Context, accountID string, filter *types.QueryFilter) (x *types.ItemList, err error)

GetItems fetches a list of items from the database that meet a particular filter.

func (*SQLQuerier) GetItemsWithIDs

func (q *SQLQuerier) GetItemsWithIDs(ctx context.Context, accountID string, limit uint8, ids []string) ([]*types.Item, error)

GetItemsWithIDs fetches items from the database within a given set of IDs.

func (*SQLQuerier) GetTotalAPIClientCount

func (q *SQLQuerier) GetTotalAPIClientCount(ctx context.Context) (uint64, error)

GetTotalAPIClientCount gets the count of API clients that match the current filter.

func (*SQLQuerier) GetTotalItemCount

func (q *SQLQuerier) GetTotalItemCount(ctx context.Context) (uint64, error)

GetTotalItemCount fetches the count of items from the database that meet a particular filter.

func (*SQLQuerier) GetUser

func (q *SQLQuerier) GetUser(ctx context.Context, userID string) (*types.User, error)

GetUser fetches a user.

func (*SQLQuerier) GetUserByUsername

func (q *SQLQuerier) GetUserByUsername(ctx context.Context, username string) (*types.User, error)

GetUserByUsername fetches a user by their username.

func (*SQLQuerier) GetUserWithUnverifiedTwoFactorSecret

func (q *SQLQuerier) GetUserWithUnverifiedTwoFactorSecret(ctx context.Context, userID string) (*types.User, error)

GetUserWithUnverifiedTwoFactorSecret fetches a user with an unverified 2FA secret.

func (*SQLQuerier) GetUsers

func (q *SQLQuerier) GetUsers(ctx context.Context, filter *types.QueryFilter) (x *types.UserList, err error)

GetUsers fetches a list of users from the database that meet a particular filter.

func (*SQLQuerier) GetWebhook

func (q *SQLQuerier) GetWebhook(ctx context.Context, webhookID, accountID string) (*types.Webhook, error)

GetWebhook fetches a webhook from the database.

func (*SQLQuerier) GetWebhooks

func (q *SQLQuerier) GetWebhooks(ctx context.Context, accountID string, filter *types.QueryFilter) (*types.WebhookList, error)

GetWebhooks fetches a list of webhooks from the database that meet a particular filter.

func (*SQLQuerier) IsReady

func (q *SQLQuerier) IsReady(ctx context.Context, maxAttempts uint8) (ready bool)

IsReady is a simple wrapper around the core querier IsReady call.

func (*SQLQuerier) ItemExists

func (q *SQLQuerier) ItemExists(ctx context.Context, itemID, accountID string) (exists bool, err error)

ItemExists fetches whether an item exists from the database.

func (*SQLQuerier) MarkAccountAsUserDefault

func (q *SQLQuerier) MarkAccountAsUserDefault(ctx context.Context, userID, accountID string) error

MarkAccountAsUserDefault does a thing.

func (*SQLQuerier) MarkUserTwoFactorSecretAsVerified

func (q *SQLQuerier) MarkUserTwoFactorSecretAsVerified(ctx context.Context, userID string) error

MarkUserTwoFactorSecretAsVerified marks a user's two factor secret as validated.

func (*SQLQuerier) Migrate

func (q *SQLQuerier) Migrate(ctx context.Context, maxAttempts uint8, testUserConfig *types.TestUserCreationConfig) error

Migrate is a simple wrapper around the core querier Migrate call.

func (*SQLQuerier) ModifyUserPermissions

func (q *SQLQuerier) ModifyUserPermissions(ctx context.Context, accountID, userID string, input *types.ModifyUserPermissionsInput) error

ModifyUserPermissions does a thing.

func (*SQLQuerier) ProvideSessionStore

func (q *SQLQuerier) ProvideSessionStore() scs.Store

ProvideSessionStore provides the scs Store for MySQL.

func (*SQLQuerier) RemoveUserFromAccount

func (q *SQLQuerier) RemoveUserFromAccount(ctx context.Context, userID, accountID string) error

RemoveUserFromAccount removes a user's membership to an account.

func (*SQLQuerier) SearchForUsersByUsername

func (q *SQLQuerier) SearchForUsersByUsername(ctx context.Context, usernameQuery string) ([]*types.User, error)

SearchForUsersByUsername fetches a list of users whose usernames begin with a given query.

func (*SQLQuerier) TransferAccountOwnership

func (q *SQLQuerier) TransferAccountOwnership(ctx context.Context, accountID string, input *types.AccountOwnershipTransferInput) error

TransferAccountOwnership does a thing.

func (*SQLQuerier) UpdateAccount

func (q *SQLQuerier) UpdateAccount(ctx context.Context, updated *types.Account) error

UpdateAccount updates a particular account. Note that UpdateAccount expects the provided input to have a valid ID.

func (*SQLQuerier) UpdateItem

func (q *SQLQuerier) UpdateItem(ctx context.Context, updated *types.Item) error

UpdateItem updates a particular item. Note that UpdateItem expects the provided input to have a valid ID.

func (*SQLQuerier) UpdateUser

func (q *SQLQuerier) UpdateUser(ctx context.Context, updated *types.User) error

UpdateUser receives a complete Requester struct and updates its record in the database. NOTE: this function uses the ID provided in the input to make its query.

func (*SQLQuerier) UpdateUserPassword

func (q *SQLQuerier) UpdateUserPassword(ctx context.Context, userID, newHash string) error

UpdateUserPassword updates a user's passwords hash in the database.

func (*SQLQuerier) UpdateUserReputation

func (q *SQLQuerier) UpdateUserReputation(ctx context.Context, userID string, input *types.UserReputationUpdateInput) error

UpdateUserReputation updates a user's account status.

func (*SQLQuerier) UpdateUserTwoFactorSecret

func (q *SQLQuerier) UpdateUserTwoFactorSecret(ctx context.Context, userID, newSecret string) error

UpdateUserTwoFactorSecret marks a user's two factor secret as validated.

func (*SQLQuerier) UserHasStatus

func (q *SQLQuerier) UserHasStatus(ctx context.Context, userID string, statuses ...string) (banned bool, err error)

UserHasStatus fetches whether an user has a particular status.

func (*SQLQuerier) UserIsMemberOfAccount

func (q *SQLQuerier) UserIsMemberOfAccount(ctx context.Context, userID, accountID string) (bool, error)

UserIsMemberOfAccount does a thing.

func (*SQLQuerier) WebhookExists

func (q *SQLQuerier) WebhookExists(ctx context.Context, webhookID, accountID string) (exists bool, err error)

WebhookExists fetches whether a webhook exists from the database.

Jump to

Keyboard shortcuts

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