database

package
Version: v0.0.0-...-99e5d07 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DB_CONNECTION_ATTEMPT = "DB_CONNECTION_ATTEMPT"
)

database operation types

Variables

This section is empty.

Functions

func ConfigureDatabaseConnection

func ConfigureDatabaseConnection(dbConn *core_database.DatabaseConn)

ConfigureDatabaseConnection configures a database connection

func GenerateRandomString

func GenerateRandomString(n int) string

func MigrateSchemas

func MigrateSchemas(db *core_database.DatabaseConn, logger core_logging.ILog, models ...interface{}) error

MigrateSchemas creates or updates a given set of model based on a schema if it does not exist or migrates the model schemas to the latest version

Types

type CmplxTx

type CmplxTx func(ctx context.Context, tx *gorm.DB) (interface{}, error)

CmplxTx is a type serving as a function decorator for complex database transactions

type Db

type Db struct {
	Conn                                     *core_database.DatabaseConn
	Logger                                   core_logging.ILog
	TracingEngine                            *core_tracing.TracingEngine
	MetricsEngine                            *core_metrics.CoreMetricsEngine
	AuthenticationHandlerServiceBaseEndpoint string
	Saga                                     *saga.SagaCoordinator
	MaxConnectionAttempts                    int
	MaxRetriesPerOperation                   int
	RetryTimeOut                             time.Duration
	OperationSleepInterval                   time.Duration
}

Db witholds connection to a postgres database as well as a logging handler

func New

func New(ctx context.Context, connectionString string, tracingEngine *core_tracing.TracingEngine, metricsEngine *core_metrics.CoreMetricsEngine,
	logger core_logging.ILog, svcEndpoint string) (*Db,
	error)

New creates a database connection and returns the connection object

func Setup

func Setup(ctx context.Context, connectionString string, tracingEngine *core_tracing.TracingEngine, metricsEngine *core_metrics.CoreMetricsEngine,
	logger core_logging.ILog, svcEndpoint string) *Db

Setup sets up database connection prior to testing

func (*Db) ArchiveBusinessAccount

func (db *Db) ArchiveBusinessAccount(ctx context.Context, id uint32) error

DeleteBusinessAccount archives a business account by id

func (*Db) ArchiveBusinessAccounts

func (db *Db) ArchiveBusinessAccounts(ctx context.Context, ids []uint32) ([]bool, error)

DeleteBusinessAccounts deletes a set of business accounts by ids

func (*Db) CreateBusinessAccount

func (db *Db) CreateBusinessAccount(ctx context.Context, account *proto.BusinessAccount, authnid uint32) (*proto.BusinessAccount, error)

CreateBusinessAccount creates a business account and saves it to the database

func (*Db) DistributedTxCreateAccount

func (db *Db) DistributedTxCreateAccount(ctx context.Context, email, password string, childSpan opentracing.Span) (*uint32, error)

DistributedTxCreateAccount creates the account record in a distributed transaction

func (*Db) DistributedTxLockAccount

func (db *Db) DistributedTxLockAccount(ctx context.Context, id uint32, childSpan opentracing.Span, token string) error

DistributedTxLockAccount locks an account in a distributed transaction

func (*Db) DistributedTxUnlockAccount

func (db *Db) DistributedTxUnlockAccount(ctx context.Context, id uint32, childSpan opentracing.Span, token string) error

DistributedTxUnlockAccount unlocks an account in a distributed transaction

func (*Db) DistributedTxUpdateAccountEmail

func (db *Db) DistributedTxUpdateAccountEmail(ctx context.Context, id uint32, email string, childSpan opentracing.Span, token string) error

DistributedTxUpdateAccountEmail updates the account record's email entry in a distributed transaction

func (*Db) GetBusinessAccount

func (db *Db) GetBusinessAccount(ctx context.Context, id uint32) (*proto.BusinessAccount, error)

GetBusinessAccount gets a singular business account

func (*Db) GetBusinessAccounts

func (db *Db) GetBusinessAccounts(ctx context.Context, ids []uint32) ([]*proto.BusinessAccount, error)

GetBusinessAccount gets a set of business accounts by ids

func (*Db) GetBusinessByEmail

func (db *Db) GetBusinessByEmail(ctx context.Context, email string) *proto.BusinessAccount

GetBusinessByEmail gets a business account by email from the backend database

func (*Db) GetBusinessById

func (db *Db) GetBusinessById(ctx context.Context, id uint32) *proto.BusinessAccount

GetBusinessById gets a business account by id from the backend database

func (*Db) GetPaginatedBusinessAccounts

func (db *Db) GetPaginatedBusinessAccounts(ctx context.Context, limit int64) ([]*proto.BusinessAccount, error)

func (*Db) PerformRetryableOperation

func (db *Db) PerformRetryableOperation(f func() error) error

func (*Db) PreloadTx

func (db *Db) PreloadTx(tx *gorm.DB) *gorm.DB

func (*Db) SetBusinessAccountStatusAndSave

func (db *Db) SetBusinessAccountStatusAndSave(ctx context.Context, businessAccount *proto.BusinessAccount,
	activateAccount bool) error

SetBusinessAccountStatusAndSave updates the active status of a business account in the backend database

func (*Db) UpdateBusinessAccount

func (db *Db) UpdateBusinessAccount(ctx context.Context, id uint32, account *proto.BusinessAccount) (*proto.BusinessAccount, error)

UpdateBusinessAccount updates a business account

type IDatabase

type IDatabase interface {
}

IDatabase provides an interface which any database tied to this service should implement

type IDbOperations

type IDbOperations interface {
	// CreateBusinessAccount creates a business account
	CreateBusinessAccount(ctx context.Context, account *proto.BusinessAccount) (*proto.BusinessAccount, error)
	// UpdateBusinessAccount updates a business account by Id
	UpdateBusinessAccount(ctx context.Context, id uint32, account *proto.BusinessAccount) (*proto.BusinessAccount, error)
	// DeleteBusinessAccount deletes a business account by Id
	ArchiveBusinessAccount(ctx context.Context, id uint32) (bool, error)
	// DeleteBusinessAccounts deletes a set of business accounts by Id
	ArchiveBusinessAccounts(ctx context.Context, ids []uint32) ([]bool, error)
	// GetBusinessAccount gets a business account by id
	GetBusinessAccount(ctx context.Context, id uint32) (*proto.BusinessAccount, error)
	// GetBusinessAccounts gets a set of business accounts by id
	GetBusinessAccounts(ctx context.Context, ids []uint32) ([]*proto.BusinessAccount, error)
}

type Tx

type Tx func(ctx context.Context, tx *gorm.DB) error

Tx is a type serving as a function decorator for common database transactions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL