Documentation ¶
Overview ¶
Package database provides interface abstractions for interacting with relational data stores
Index ¶
- Variables
- func BoolFromNullBool(b sql.NullBool) bool
- func Float32FromNullString(s sql.NullString) float32
- func Float32FromString(s string) float32
- func Float32PointerFromNullString(f sql.NullString) *float32
- func Float64PointerFromNullString(f sql.NullString) *float64
- func Int32PointerFromNullInt32(i sql.NullInt32) *int32
- func NullBoolFromBool(b bool) sql.NullBool
- func NullInt32FromInt32Pointer(i *int32) sql.NullInt32
- func NullInt32FromUint16(i uint16) sql.NullInt32
- func NullInt32FromUint16Pointer(i *uint16) sql.NullInt32
- func NullInt32FromUint32Pointer(i *uint32) sql.NullInt32
- func NullInt32FromUint8Pointer(i *uint8) sql.NullInt32
- func NullInt64FromUint32Pointer(f *uint32) sql.NullInt64
- func NullStringFromFloat32(f float32) sql.NullString
- func NullStringFromFloat32Pointer(f *float32) sql.NullString
- func NullStringFromFloat64Pointer(f *float64) sql.NullString
- func NullStringFromString(s string) sql.NullString
- func NullStringFromStringPointer(s *string) sql.NullString
- func NullTimeFromTime(t time.Time) sql.NullTime
- func NullTimeFromTimePointer(t *time.Time) sql.NullTime
- func ProvideAccountDataManager(db DataManager) types.AccountDataManager
- func ProvideAccountInvitationDataManager(db DataManager) types.AccountInvitationDataManager
- func ProvideAccountUserMembershipDataManager(db DataManager) types.AccountUserMembershipDataManager
- func ProvideAdminUserDataManager(db DataManager) types.AdminUserDataManager
- func ProvideAuditLogEntryDataManager(db DataManager) types.AuditLogEntryDataManager
- func ProvideOAuth2ClientDataManager(db DataManager) types.OAuth2ClientDataManager
- func ProvidePasswordResetTokenDataManager(db DataManager) types.PasswordResetTokenDataManager
- func ProvideServiceSettingConfigurationDataManager(db DataManager) types.ServiceSettingConfigurationDataManager
- func ProvideServiceSettingDataManager(db DataManager) types.ServiceSettingDataManager
- func ProvideUserDataManager(db DataManager) types.UserDataManager
- func ProvideUserNotificationDataManager(db DataManager) types.UserNotificationDataManager
- func ProvideWebhookDataManager(db DataManager) types.WebhookDataManager
- func StringFromFloat32(f float32) string
- func StringFromFloat64(f float64) string
- func StringFromNullString(nt sql.NullString) string
- func StringPointerFromNullString(nt sql.NullString) *string
- func TimePointerFromNullTime(nt sql.NullTime) *time.Time
- func Uint16PointerFromNullInt32(f sql.NullInt32) *uint16
- func Uint32PointerFromNullInt32(f sql.NullInt32) *uint32
- func Uint32PointerFromNullInt64(f sql.NullInt64) *uint32
- type DataManager
- type MockDatabase
- func (m *MockDatabase) BeginTx(ctx context.Context, options *sql.TxOptions) (*sql.Tx, error)
- func (m *MockDatabase) Close()
- func (m *MockDatabase) DB() *sql.DB
- func (m *MockDatabase) IsReady(ctx context.Context, waitPeriod time.Duration, maxAttempts uint64) (ready bool)
- func (m *MockDatabase) Migrate(ctx context.Context, waitPeriod time.Duration, maxAttempts uint64) error
- func (m *MockDatabase) ProvideSessionStore() scs.Store
- type MockQueryExecutor
- func (m *MockQueryExecutor) ExecContext(ctx context.Context, query string, queryArgs ...any) (sql.Result, error)
- func (m *MockQueryExecutor) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (m *MockQueryExecutor) QueryContext(ctx context.Context, query string, queryArgs ...any) (*sql.Rows, error)
- func (m *MockQueryExecutor) QueryRowContext(ctx context.Context, query string, queryArgs ...any) *sql.Row
- type MockResultIterator
- type MockSQLResult
- type ResultIterator
- type SQLQueryExecutor
- type SQLQueryExecutorAndTransactionManager
- type SQLTransactionManager
- type Scanner
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDatabaseNotReady indicates the given database is not ready. ErrDatabaseNotReady = errors.New("database is not ready yet") // ErrUserAlreadyExists indicates that a user with that username has already been created. ErrUserAlreadyExists = errors.New("user already exists") )
var ( // DBProviders represents what we provide to dependency injectors. DBProviders = wire.NewSet( ProvideAccountDataManager, ProvideAccountInvitationDataManager, ProvideAccountUserMembershipDataManager, ProvideUserDataManager, ProvideAdminUserDataManager, ProvidePasswordResetTokenDataManager, ProvideWebhookDataManager, ProvideServiceSettingDataManager, ProvideServiceSettingConfigurationDataManager, ProvideOAuth2ClientDataManager, ProvideUserNotificationDataManager, ProvideAuditLogEntryDataManager, ) )
Functions ¶
func BoolFromNullBool ¶
func Float32FromNullString ¶
func Float32FromNullString(s sql.NullString) float32
func Float32FromString ¶
func Float32PointerFromNullString ¶
func Float32PointerFromNullString(f sql.NullString) *float32
func Float64PointerFromNullString ¶
func Float64PointerFromNullString(f sql.NullString) *float64
func NullBoolFromBool ¶
func NullInt32FromUint16 ¶
func NullStringFromFloat32 ¶
func NullStringFromFloat32(f float32) sql.NullString
func NullStringFromFloat32Pointer ¶
func NullStringFromFloat32Pointer(f *float32) sql.NullString
func NullStringFromFloat64Pointer ¶
func NullStringFromFloat64Pointer(f *float64) sql.NullString
func NullStringFromString ¶
func NullStringFromString(s string) sql.NullString
func NullStringFromStringPointer ¶
func NullStringFromStringPointer(s *string) sql.NullString
func ProvideAccountDataManager ¶
func ProvideAccountDataManager(db DataManager) types.AccountDataManager
ProvideAccountDataManager is an arbitrary function for dependency injection's sake.
func ProvideAccountInvitationDataManager ¶
func ProvideAccountInvitationDataManager(db DataManager) types.AccountInvitationDataManager
ProvideAccountInvitationDataManager is an arbitrary function for dependency injection's sake.
func ProvideAccountUserMembershipDataManager ¶
func ProvideAccountUserMembershipDataManager(db DataManager) types.AccountUserMembershipDataManager
ProvideAccountUserMembershipDataManager is an arbitrary function for dependency injection's sake.
func ProvideAdminUserDataManager ¶
func ProvideAdminUserDataManager(db DataManager) types.AdminUserDataManager
ProvideAdminUserDataManager is an arbitrary function for dependency injection's sake.
func ProvideAuditLogEntryDataManager ¶
func ProvideAuditLogEntryDataManager(db DataManager) types.AuditLogEntryDataManager
ProvideAuditLogEntryDataManager is an arbitrary function for dependency injection's sake.
func ProvideOAuth2ClientDataManager ¶
func ProvideOAuth2ClientDataManager(db DataManager) types.OAuth2ClientDataManager
ProvideOAuth2ClientDataManager is an arbitrary function for dependency injection's sake.
func ProvidePasswordResetTokenDataManager ¶
func ProvidePasswordResetTokenDataManager(db DataManager) types.PasswordResetTokenDataManager
ProvidePasswordResetTokenDataManager is an arbitrary function for dependency injection's sake.
func ProvideServiceSettingConfigurationDataManager ¶
func ProvideServiceSettingConfigurationDataManager(db DataManager) types.ServiceSettingConfigurationDataManager
ProvideServiceSettingConfigurationDataManager is an arbitrary function for dependency injection's sake.
func ProvideServiceSettingDataManager ¶
func ProvideServiceSettingDataManager(db DataManager) types.ServiceSettingDataManager
ProvideServiceSettingDataManager is an arbitrary function for dependency injection's sake.
func ProvideUserDataManager ¶
func ProvideUserDataManager(db DataManager) types.UserDataManager
ProvideUserDataManager is an arbitrary function for dependency injection's sake.
func ProvideUserNotificationDataManager ¶
func ProvideUserNotificationDataManager(db DataManager) types.UserNotificationDataManager
ProvideUserNotificationDataManager is an arbitrary function for dependency injection's sake.
func ProvideWebhookDataManager ¶
func ProvideWebhookDataManager(db DataManager) types.WebhookDataManager
ProvideWebhookDataManager is an arbitrary function for dependency injection's sake.
func StringFromFloat32 ¶
func StringFromFloat64 ¶
func StringFromNullString ¶
func StringFromNullString(nt sql.NullString) string
func StringPointerFromNullString ¶
func StringPointerFromNullString(nt sql.NullString) *string
Types ¶
type DataManager ¶
type DataManager interface { DB() *sql.DB Close() Migrate(ctx context.Context, waitPeriod time.Duration, maxAttempts uint64) error IsReady(ctx context.Context, waitPeriod time.Duration, maxAttempts uint64) (ready bool) ProvideSessionStore() scs.Store types.AdminUserDataManager types.AccountDataManager types.AccountInvitationDataManager types.AccountUserMembershipDataManager types.UserDataManager types.PasswordResetTokenDataManager types.WebhookDataManager types.ServiceSettingDataManager types.ServiceSettingConfigurationDataManager types.OAuth2ClientDataManager types.OAuth2ClientTokenDataManager types.UserNotificationDataManager types.AuditLogEntryDataManager }
DataManager describes anything that stores data for our services.
type MockDatabase ¶
type MockDatabase struct { *mocktypes.AdminUserDataManagerMock *mocktypes.AccountUserMembershipDataManagerMock *mocktypes.UserDataManagerMock *mocktypes.PasswordResetTokenDataManagerMock *mocktypes.WebhookDataManagerMock *mocktypes.AccountDataManagerMock *mocktypes.AccountInvitationDataManagerMock *mocktypes.ServiceSettingDataManagerMock *mocktypes.ServiceSettingConfigurationDataManagerMock *mocktypes.OAuth2ClientDataManagerMock *mocktypes.OAuth2ClientTokenDataManagerMock *mocktypes.UserNotificationDataManagerMock *mocktypes.AuditLogEntryDataManagerMock mock.Mock }
MockDatabase is our mock database structure. Note, when using this in tests, you must directly access the type name of all the implicit fields. So `mockDB.On("GetUserByUsername"...)` is destined to fail, whereas `mockDB.UserDataManagerMock.On("GetUserByUsername"...)` would do what you want it to do.
func (*MockDatabase) Close ¶
func (m *MockDatabase) Close()
Close satisfies the DataManager interface.
func (*MockDatabase) DB ¶
func (m *MockDatabase) DB() *sql.DB
DB satisfies the DataManager interface.
func (*MockDatabase) IsReady ¶
func (m *MockDatabase) IsReady(ctx context.Context, waitPeriod time.Duration, maxAttempts uint64) (ready bool)
IsReady satisfies the DataManager interface.
func (*MockDatabase) Migrate ¶
func (m *MockDatabase) Migrate(ctx context.Context, waitPeriod time.Duration, maxAttempts uint64) error
Migrate satisfies the DataManager interface.
func (*MockDatabase) ProvideSessionStore ¶
func (m *MockDatabase) ProvideSessionStore() scs.Store
ProvideSessionStore satisfies the DataManager interface.
type MockQueryExecutor ¶
MockQueryExecutor mocks a sql.Tx|DB.
func (*MockQueryExecutor) ExecContext ¶
func (m *MockQueryExecutor) ExecContext(ctx context.Context, query string, queryArgs ...any) (sql.Result, error)
ExecContext is a mock function.
func (*MockQueryExecutor) PrepareContext ¶
PrepareContext is a mock function.
func (*MockQueryExecutor) QueryContext ¶
func (m *MockQueryExecutor) QueryContext(ctx context.Context, query string, queryArgs ...any) (*sql.Rows, error)
QueryContext is a mock function.
func (*MockQueryExecutor) QueryRowContext ¶
func (m *MockQueryExecutor) QueryRowContext(ctx context.Context, query string, queryArgs ...any) *sql.Row
QueryRowContext is a mock function.
type MockResultIterator ¶
MockResultIterator is our mock sql.Rows structure.
func (*MockResultIterator) Close ¶
func (m *MockResultIterator) Close() error
Close satisfies the ResultIterator interface.
func (*MockResultIterator) Err ¶
func (m *MockResultIterator) Err() error
Err satisfies the ResultIterator interface.
func (*MockResultIterator) Next ¶
func (m *MockResultIterator) Next() bool
Next satisfies the ResultIterator interface.
func (*MockResultIterator) Scan ¶
func (m *MockResultIterator) Scan(dest ...any) error
Scan satisfies the ResultIterator interface.
type MockSQLResult ¶
MockSQLResult mocks a sql.Result.
func (*MockSQLResult) LastInsertId ¶
func (m *MockSQLResult) LastInsertId() (int64, error)
LastInsertId implements our interface.
func (*MockSQLResult) RowsAffected ¶
func (m *MockSQLResult) RowsAffected() (int64, error)
RowsAffected implements our interface.
type ResultIterator ¶
ResultIterator represents any iterable database response (i.e. sql.Rows).
type SQLQueryExecutor ¶
type SQLQueryExecutor interface { ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) PrepareContext(context.Context, string) (*sql.Stmt, error) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }
SQLQueryExecutor is a subset interface for sql.{DB|Tx} objects.
type SQLQueryExecutorAndTransactionManager ¶
type SQLQueryExecutorAndTransactionManager interface { SQLQueryExecutor SQLTransactionManager }
SQLQueryExecutorAndTransactionManager is a subset interface for sql.{DB|Tx} objects.
type SQLTransactionManager ¶
type SQLTransactionManager interface {
Rollback() error
}
SQLTransactionManager is a subset interface for sql.{DB|Tx} objects.