database

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: 12 Imported by: 0

Documentation

Overview

Package database provides interface abstractions for interacting with relational data stores

Index

Constants

This section is empty.

Variables

View Source
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")
)

Functions

func BoolFromNullBool

func BoolFromNullBool(b sql.NullBool) bool

func Float32FromNullString

func Float32FromNullString(s sql.NullString) float32

func Float32FromString

func Float32FromString(s string) float32

func Float32PointerFromNullString

func Float32PointerFromNullString(f sql.NullString) *float32

func Float64PointerFromNullString

func Float64PointerFromNullString(f sql.NullString) *float64

func Int32PointerFromNullInt32

func Int32PointerFromNullInt32(i sql.NullInt32) *int32

func NullBoolFromBool

func NullBoolFromBool(b bool) sql.NullBool

func NullInt32FromInt32Pointer

func NullInt32FromInt32Pointer(i *int32) sql.NullInt32

func NullInt32FromUint16

func NullInt32FromUint16(i uint16) sql.NullInt32

func NullInt32FromUint16Pointer

func NullInt32FromUint16Pointer(i *uint16) sql.NullInt32

func NullInt32FromUint32Pointer

func NullInt32FromUint32Pointer(i *uint32) sql.NullInt32

func NullInt32FromUint8Pointer

func NullInt32FromUint8Pointer(i *uint8) sql.NullInt32

func NullInt64FromUint32Pointer

func NullInt64FromUint32Pointer(f *uint32) sql.NullInt64

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 NullTimeFromTime

func NullTimeFromTime(t time.Time) sql.NullTime

func NullTimeFromTimePointer

func NullTimeFromTimePointer(t *time.Time) sql.NullTime

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 StringFromFloat32(f float32) string

func StringFromFloat64

func StringFromFloat64(f float64) string

func StringFromNullString

func StringFromNullString(nt sql.NullString) string

func StringPointerFromNullString

func StringPointerFromNullString(nt sql.NullString) *string

func TimePointerFromNullTime

func TimePointerFromNullTime(nt sql.NullTime) *time.Time

func Uint16PointerFromNullInt32

func Uint16PointerFromNullInt32(f sql.NullInt32) *uint16

func Uint32PointerFromNullInt32

func Uint32PointerFromNullInt32(f sql.NullInt32) *uint32

func Uint32PointerFromNullInt64

func Uint32PointerFromNullInt64(f sql.NullInt64) *uint32

Types

type MockDatabase

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 NewMockDatabase

func NewMockDatabase() *MockDatabase

NewMockDatabase builds a mock database.

func (*MockDatabase) BeginTx

func (m *MockDatabase) BeginTx(ctx context.Context, options *sql.TxOptions) (*sql.Tx, error)

BeginTx satisfies the DataManager interface.

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

type MockQueryExecutor struct {
	mock.Mock
}

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

func (m *MockQueryExecutor) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

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

type MockResultIterator struct {
	mock.Mock
}

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

type MockSQLResult struct {
	mock.Mock
}

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

type ResultIterator interface {
	Next() bool
	Err() error
	Scanner
	io.Closer
}

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.

type Scanner

type Scanner interface {
	Scan(dest ...any) error
}

Scanner represents any database response (i.e. sql.Row[s]).

Directories

Path Synopsis
Package postgres provides an interface for writing to a Postgres instance.
Package postgres provides an interface for writing to a Postgres instance.

Jump to

Keyboard shortcuts

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