postgres

package
v0.0.0-...-98cd694 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Unlicense Imports: 29 Imported by: 0

Documentation

Overview

Package postgres provides an interface for writing to a Postgres 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")

	// 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")
)
View Source
var (
	// ProvidersPostgres are what we offer to dependency injection.
	ProvidersPostgres = wire.NewSet(
		ProvideDatabaseClient,
	)
)

Functions

func ProvideDatabaseClient

func ProvideDatabaseClient(ctx context.Context, logger logging.Logger, tracerProvider tracing.TracerProvider, cfg *dbconfig.Config) (database.DataManager, error)

ProvideDatabaseClient provides a new DataManager client.

Types

type Querier

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

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

func (*Querier) AcceptAccountInvitation

func (q *Querier) AcceptAccountInvitation(ctx context.Context, accountInvitationID, token, note string) error

AcceptAccountInvitation accepts a account invitation by its ID with a note.

func (*Querier) AccountInvitationExists

func (q *Querier) AccountInvitationExists(ctx context.Context, accountInvitationID string) (bool, error)

AccountInvitationExists fetches whether a account invitation exists from the database.

func (*Querier) ArchiveAccount

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

ArchiveAccount archives a account from the database by its ID.

func (*Querier) ArchiveOAuth2Client

func (q *Querier) ArchiveOAuth2Client(ctx context.Context, clientID string) error

ArchiveOAuth2Client archives an OAuth2 client.

func (*Querier) ArchiveOAuth2ClientTokenByAccess

func (q *Querier) ArchiveOAuth2ClientTokenByAccess(ctx context.Context, access string) error

ArchiveOAuth2ClientTokenByAccess archives an OAuth2 client token from the database by its ID.

func (*Querier) ArchiveOAuth2ClientTokenByCode

func (q *Querier) ArchiveOAuth2ClientTokenByCode(ctx context.Context, code string) error

ArchiveOAuth2ClientTokenByCode archives an OAuth2 client token from the database by its ID.

func (*Querier) ArchiveOAuth2ClientTokenByRefresh

func (q *Querier) ArchiveOAuth2ClientTokenByRefresh(ctx context.Context, refresh string) error

ArchiveOAuth2ClientTokenByRefresh archives an OAuth2 client token from the database by its ID.

func (*Querier) ArchiveServiceSetting

func (q *Querier) ArchiveServiceSetting(ctx context.Context, serviceSettingID string) error

ArchiveServiceSetting archives a service setting from the database by its ID.

func (*Querier) ArchiveServiceSettingConfiguration

func (q *Querier) ArchiveServiceSettingConfiguration(ctx context.Context, serviceSettingConfigurationID string) error

ArchiveServiceSettingConfiguration archives a service setting configuration from the database by its ID.

func (*Querier) ArchiveUser

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

ArchiveUser archives a user.

func (*Querier) ArchiveWebhook

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

ArchiveWebhook archives a webhook from the database.

func (*Querier) ArchiveWebhookTriggerEvent

func (q *Querier) ArchiveWebhookTriggerEvent(ctx context.Context, webhookID, webhookTriggerEventID string) error

ArchiveWebhookTriggerEvent archives a webhook trigger event from the database.

func (*Querier) BuildSessionContextDataForUser

func (q *Querier) 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 (*Querier) CancelAccountInvitation

func (q *Querier) CancelAccountInvitation(ctx context.Context, accountInvitationID, note string) error

CancelAccountInvitation cancels a account invitation by its ID with a note.

func (*Querier) Close

func (q *Querier) Close()

Close closes the database connection.

func (*Querier) CreateAccount

func (q *Querier) CreateAccount(ctx context.Context, input *types.AccountDatabaseCreationInput) (*types.Account, error)

CreateAccount creates a account in the database.

func (*Querier) CreateAccountInvitation

CreateAccountInvitation creates an invitation in a database.

func (*Querier) CreateOAuth2Client

func (q *Querier) CreateOAuth2Client(ctx context.Context, input *types.OAuth2ClientDatabaseCreationInput) (*types.OAuth2Client, error)

CreateOAuth2Client creates an OAuth2 client.

func (*Querier) CreateOAuth2ClientToken

CreateOAuth2ClientToken creates an OAuth2 client token in the database.

func (*Querier) CreatePasswordResetToken

CreatePasswordResetToken creates a password reset token in the database.

func (*Querier) CreateServiceSetting

func (q *Querier) CreateServiceSetting(ctx context.Context, input *types.ServiceSettingDatabaseCreationInput) (*types.ServiceSetting, error)

CreateServiceSetting creates a service setting in the database.

func (*Querier) CreateServiceSettingConfiguration

CreateServiceSettingConfiguration creates a service setting configuration in the database.

func (*Querier) CreateUser

func (q *Querier) CreateUser(ctx context.Context, input *types.UserDatabaseCreationInput) (*types.User, error)

CreateUser creates a user. TODO: this should return a account as well.

func (*Querier) CreateUserNotification

CreateUserNotification creates a user notification in the database.

func (*Querier) CreateWebhook

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

CreateWebhook creates a webhook in a database.

func (*Querier) DB

func (q *Querier) DB() *sql.DB

DB provides the database object.

func (*Querier) GetAccount

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

GetAccount fetches a account from the database.

func (*Querier) GetAccountInvitationByAccountAndID

func (q *Querier) GetAccountInvitationByAccountAndID(ctx context.Context, accountID, accountInvitationID string) (*types.AccountInvitation, error)

GetAccountInvitationByAccountAndID fetches an invitation from the database.

func (*Querier) GetAccountInvitationByEmailAndToken

func (q *Querier) GetAccountInvitationByEmailAndToken(ctx context.Context, emailAddress, token string) (*types.AccountInvitation, error)

GetAccountInvitationByEmailAndToken fetches an invitation from the database.

func (*Querier) GetAccountInvitationByTokenAndID

func (q *Querier) GetAccountInvitationByTokenAndID(ctx context.Context, token, invitationID string) (*types.AccountInvitation, error)

GetAccountInvitationByTokenAndID fetches an invitation from the database.

func (*Querier) GetAccounts

func (q *Querier) GetAccounts(ctx context.Context, userID string, filter *types.QueryFilter) (x *types.QueryFilteredResult[types.Account], err error)

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

func (*Querier) GetAdminUserByUsername

func (q *Querier) GetAdminUserByUsername(ctx context.Context, username string) (*types.User, error)

GetAdminUserByUsername fetches a user by their username.

func (*Querier) GetAuditLogEntriesForAccount

func (q *Querier) GetAuditLogEntriesForAccount(ctx context.Context, accountID string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.AuditLogEntry], error)

GetAuditLogEntriesForAccount fetches a list of audit log entries from the database that meet a particular filter.

func (*Querier) GetAuditLogEntriesForAccountAndResourceType

func (q *Querier) GetAuditLogEntriesForAccountAndResourceType(ctx context.Context, accountID string, resourceTypes []string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.AuditLogEntry], error)

GetAuditLogEntriesForAccountAndResourceType fetches a list of audit log entries from the database that meet a particular filter.

func (*Querier) GetAuditLogEntriesForUser

func (q *Querier) GetAuditLogEntriesForUser(ctx context.Context, userID string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.AuditLogEntry], error)

GetAuditLogEntriesForUser fetches a list of audit log entries from the database that meet a particular filter.

func (*Querier) GetAuditLogEntriesForUserAndResourceType

func (q *Querier) GetAuditLogEntriesForUserAndResourceType(ctx context.Context, userID string, resourceTypes []string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.AuditLogEntry], error)

GetAuditLogEntriesForUserAndResourceType fetches a list of audit log entries from the database that meet a particular filter.

func (*Querier) GetAuditLogEntry

func (q *Querier) GetAuditLogEntry(ctx context.Context, auditLogEntryID string) (*types.AuditLogEntry, error)

GetAuditLogEntry fetches an audit log entry from the database.

func (*Querier) GetDefaultAccountIDForUser

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

GetDefaultAccountIDForUser retrieves the default account ID for a user.

func (*Querier) GetEmailAddressVerificationTokenForUser

func (q *Querier) GetEmailAddressVerificationTokenForUser(ctx context.Context, userID string) (string, error)

func (*Querier) GetOAuth2ClientByClientID

func (q *Querier) GetOAuth2ClientByClientID(ctx context.Context, clientID string) (*types.OAuth2Client, error)

GetOAuth2ClientByClientID gets an OAuth2 client from the database.

func (*Querier) GetOAuth2ClientByDatabaseID

func (q *Querier) GetOAuth2ClientByDatabaseID(ctx context.Context, clientID string) (*types.OAuth2Client, error)

GetOAuth2ClientByDatabaseID gets an OAuth2 client from the database.

func (*Querier) GetOAuth2ClientTokenByAccess

func (q *Querier) GetOAuth2ClientTokenByAccess(ctx context.Context, access string) (*types.OAuth2ClientToken, error)

GetOAuth2ClientTokenByAccess fetches an OAuth2 client token from the database.

func (*Querier) GetOAuth2ClientTokenByCode

func (q *Querier) GetOAuth2ClientTokenByCode(ctx context.Context, code string) (*types.OAuth2ClientToken, error)

GetOAuth2ClientTokenByCode fetches an OAuth2 client token from the database.

func (*Querier) GetOAuth2ClientTokenByRefresh

func (q *Querier) GetOAuth2ClientTokenByRefresh(ctx context.Context, refresh string) (*types.OAuth2ClientToken, error)

GetOAuth2ClientTokenByRefresh fetches an OAuth2 client token from the database.

func (*Querier) GetOAuth2Clients

func (q *Querier) GetOAuth2Clients(ctx context.Context, filter *types.QueryFilter) (x *types.QueryFilteredResult[types.OAuth2Client], err error)

GetOAuth2Clients gets a list of OAuth2 clients.

func (*Querier) GetPasswordResetTokenByToken

func (q *Querier) GetPasswordResetTokenByToken(ctx context.Context, token string) (*types.PasswordResetToken, error)

GetPasswordResetTokenByToken fetches a password reset token from the database by its token.

func (*Querier) GetPendingAccountInvitationsForUser

func (q *Querier) GetPendingAccountInvitationsForUser(ctx context.Context, userID string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.AccountInvitation], error)

GetPendingAccountInvitationsForUser fetches pending account invitations sent to a given user.

func (*Querier) GetPendingAccountInvitationsFromUser

func (q *Querier) GetPendingAccountInvitationsFromUser(ctx context.Context, userID string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.AccountInvitation], error)

GetPendingAccountInvitationsFromUser fetches pending account invitations sent from a given user.

func (*Querier) GetServiceSetting

func (q *Querier) GetServiceSetting(ctx context.Context, serviceSettingID string) (*types.ServiceSetting, error)

GetServiceSetting fetches a service setting from the database.

func (*Querier) GetServiceSettingConfiguration

func (q *Querier) GetServiceSettingConfiguration(ctx context.Context, serviceSettingConfigurationID string) (*types.ServiceSettingConfiguration, error)

GetServiceSettingConfiguration fetches a service setting configuration from the database.

func (*Querier) GetServiceSettingConfigurationForAccountByName

func (q *Querier) GetServiceSettingConfigurationForAccountByName(ctx context.Context, accountID, settingName string) (*types.ServiceSettingConfiguration, error)

GetServiceSettingConfigurationForAccountByName fetches a service setting configuration from the database.

func (*Querier) GetServiceSettingConfigurationForUserByName

func (q *Querier) GetServiceSettingConfigurationForUserByName(ctx context.Context, userID, settingName string) (*types.ServiceSettingConfiguration, error)

GetServiceSettingConfigurationForUserByName fetches a service setting configuration from the database.

func (*Querier) GetServiceSettingConfigurationsForAccount

func (q *Querier) GetServiceSettingConfigurationsForAccount(ctx context.Context, accountID string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.ServiceSettingConfiguration], error)

GetServiceSettingConfigurationsForAccount fetches a list of service setting configurations from the database that meet a particular filter.

func (*Querier) GetServiceSettingConfigurationsForUser

func (q *Querier) GetServiceSettingConfigurationsForUser(ctx context.Context, userID string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.ServiceSettingConfiguration], error)

GetServiceSettingConfigurationsForUser fetches a list of service setting configurations from the database that meet a particular filter.

func (*Querier) GetServiceSettings

func (q *Querier) GetServiceSettings(ctx context.Context, filter *types.QueryFilter) (x *types.QueryFilteredResult[types.ServiceSetting], err error)

GetServiceSettings fetches a list of service settings from the database that meet a particular filter.

func (*Querier) GetUser

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

GetUser fetches a user.

func (*Querier) GetUserByEmail

func (q *Querier) GetUserByEmail(ctx context.Context, email string) (*types.User, error)

GetUserByEmail fetches a user by their email.

func (*Querier) GetUserByEmailAddressVerificationToken

func (q *Querier) GetUserByEmailAddressVerificationToken(ctx context.Context, token string) (*types.User, error)

func (*Querier) GetUserByUsername

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

GetUserByUsername fetches a user by their username.

func (*Querier) GetUserIDsThatNeedSearchIndexing

func (q *Querier) GetUserIDsThatNeedSearchIndexing(ctx context.Context) ([]string, error)

GetUserIDsThatNeedSearchIndexing fetches a list of valid vessels from the database that meet a particular filter.

func (*Querier) GetUserNotification

func (q *Querier) GetUserNotification(ctx context.Context, userID, userNotificationID string) (*types.UserNotification, error)

GetUserNotification fetches a user notification from the database.

func (*Querier) GetUserNotifications

func (q *Querier) GetUserNotifications(ctx context.Context, userID string, filter *types.QueryFilter) (x *types.QueryFilteredResult[types.UserNotification], err error)

GetUserNotifications fetches a list of user notifications from the database that meet a particular filter.

func (*Querier) GetUserWithUnverifiedTwoFactorSecret

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

GetUserWithUnverifiedTwoFactorSecret fetches a user with an unverified 2FA secret.

func (*Querier) GetUsers

func (q *Querier) GetUsers(ctx context.Context, filter *types.QueryFilter) (x *types.QueryFilteredResult[types.User], err error)

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

func (*Querier) GetWebhook

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

GetWebhook fetches a webhook from the database.

func (*Querier) GetWebhooks

func (q *Querier) GetWebhooks(ctx context.Context, accountID string, filter *types.QueryFilter) (*types.QueryFilteredResult[types.Webhook], error)

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

func (*Querier) GetWebhooksForAccountAndEvent

func (q *Querier) GetWebhooksForAccountAndEvent(ctx context.Context, accountID string, eventType types.ServiceEventType) ([]*types.Webhook, error)

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

func (*Querier) IsReady

func (q *Querier) IsReady(ctx context.Context, waitPeriod time.Duration, maxAttempts uint64) (ready bool)

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

func (*Querier) MarkAccountAsUserDefault

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

MarkAccountAsUserDefault does a thing.

func (*Querier) MarkUserAsIndexed

func (q *Querier) MarkUserAsIndexed(ctx context.Context, userID string) error

MarkUserAsIndexed updates a particular user's last_indexed_at value.

func (*Querier) MarkUserEmailAddressAsUnverified

func (q *Querier) MarkUserEmailAddressAsUnverified(ctx context.Context, userID string) error

func (*Querier) MarkUserEmailAddressAsVerified

func (q *Querier) MarkUserEmailAddressAsVerified(ctx context.Context, userID, token string) error

func (*Querier) MarkUserTwoFactorSecretAsUnverified

func (q *Querier) MarkUserTwoFactorSecretAsUnverified(ctx context.Context, userID, newSecret string) error

MarkUserTwoFactorSecretAsUnverified marks a user's two factor secret as unverified.

func (*Querier) MarkUserTwoFactorSecretAsVerified

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

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

func (*Querier) Migrate

func (q *Querier) Migrate(ctx context.Context, waitPeriod time.Duration, maxAttempts uint64) error

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

func (*Querier) ModifyUserPermissions

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

ModifyUserPermissions does a thing.

func (*Querier) ProvideSessionStore

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

ProvideSessionStore provides the scs Store for Postgres.

func (*Querier) RedeemPasswordResetToken

func (q *Querier) RedeemPasswordResetToken(ctx context.Context, passwordResetTokenID string) error

RedeemPasswordResetToken redeems a password reset token from the database by its ID.

func (*Querier) RejectAccountInvitation

func (q *Querier) RejectAccountInvitation(ctx context.Context, accountInvitationID, note string) error

RejectAccountInvitation rejects a account invitation by its ID with a note.

func (*Querier) RemoveUserFromAccount

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

RemoveUserFromAccount removes a user's membership to a account.

func (*Querier) SearchForServiceSettings

func (q *Querier) SearchForServiceSettings(ctx context.Context, query string) ([]*types.ServiceSetting, error)

SearchForServiceSettings fetches a service setting from the database.

func (*Querier) SearchForUsersByUsername

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

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

func (*Querier) ServiceSettingConfigurationExists

func (q *Querier) ServiceSettingConfigurationExists(ctx context.Context, serviceSettingConfigurationID string) (exists bool, err error)

ServiceSettingConfigurationExists fetches whether a service setting configuration exists from the database.

func (*Querier) ServiceSettingExists

func (q *Querier) ServiceSettingExists(ctx context.Context, serviceSettingID string) (exists bool, err error)

ServiceSettingExists fetches whether a service setting exists from the database.

func (*Querier) TransferAccountOwnership

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

TransferAccountOwnership does a thing.

func (*Querier) UpdateAccount

func (q *Querier) 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 (*Querier) UpdateServiceSettingConfiguration

func (q *Querier) UpdateServiceSettingConfiguration(ctx context.Context, updated *types.ServiceSettingConfiguration) error

UpdateServiceSettingConfiguration updates a particular service setting configuration.

func (*Querier) UpdateUserAccountStatus

func (q *Querier) UpdateUserAccountStatus(ctx context.Context, userID string, input *types.UserAccountStatusUpdateInput) error

UpdateUserAccountStatus updates a user's account status.

func (*Querier) UpdateUserAvatar

func (q *Querier) UpdateUserAvatar(ctx context.Context, userID, newAvatarSrc string) error

UpdateUserAvatar updates a user's avatar source.

func (*Querier) UpdateUserDetails

func (q *Querier) UpdateUserDetails(ctx context.Context, userID string, input *types.UserDetailsDatabaseUpdateInput) error

UpdateUserDetails updates a user's username.

func (*Querier) UpdateUserEmailAddress

func (q *Querier) UpdateUserEmailAddress(ctx context.Context, userID, newEmailAddress string) error

UpdateUserEmailAddress updates a user's username.

func (*Querier) UpdateUserNotification

func (q *Querier) UpdateUserNotification(ctx context.Context, updated *types.UserNotification) error

UpdateUserNotification updates a particular user notification.

func (*Querier) UpdateUserPassword

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

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

func (*Querier) UpdateUserTwoFactorSecret

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

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

func (*Querier) UpdateUserUsername

func (q *Querier) UpdateUserUsername(ctx context.Context, userID, newUsername string) error

UpdateUserUsername updates a user's username.

func (*Querier) UserIsMemberOfAccount

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

UserIsMemberOfAccount does a thing.

func (*Querier) UserNotificationExists

func (q *Querier) UserNotificationExists(ctx context.Context, userID, userNotificationID string) (exists bool, err error)

UserNotificationExists fetches whether a user notification exists from the database.

func (*Querier) WebhookExists

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

WebhookExists fetches whether a webhook exists from the database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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