database

package
v0.0.0-...-eac6ddc Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxConnectionAttempts  int           = 3
	DefaultMaxRetriesPerOperation int           = 3
	DefaultRetryTimeout           time.Duration = 50 * time.Millisecond
	DefaultRetrySleepInterval     time.Duration = 25 * time.Millisecond
)
View Source
const (
	EMPTY = ""
)

Variables

View Source
var (
	Conn                *Db
	Port                int    = 6000
	Host                string = "localhost"
	User                string = "merchant_component"
	Password            string = "merchant_component"
	Dbname              string = "merchant_component"
	DefaultDbConnParams        = helper.DatabaseConnectionParams{
		Host:         Host,
		User:         User,
		Password:     Password,
		DatabaseName: Dbname,
		Port:         Port,
	}

	DefaultConnInitializationParams = ConnectionInitializationParams{
		ConnectionParams:       &DefaultDbConnParams,
		Logger:                 zap.L(),
		MaxConnectionAttempts:  DefaultMaxConnectionAttempts,
		MaxRetriesPerOperation: DefaultMaxRetriesPerOperation,
		RetryTimeOut:           DefaultRetryTimeout,
		RetrySleepInterval:     DefaultRetrySleepInterval,
	}
)

Functions

func GenerateRandomId

func GenerateRandomId(min, max int) int

GenerateRandomId generates a random id over a range

func GenerateRandomizedAccount

func GenerateRandomizedAccount() *models.MerchantAccount

GenerateRandomizedAccount generates a random account

func GenerateRandomizedAccountWithRandomId

func GenerateRandomizedAccountWithRandomId() *models.MerchantAccount

func SetupTestDbConn

func SetupTestDbConn()

SetupTestDbConn sets up a database connection to the test db node

Types

type ConnectionInitializationParams

type ConnectionInitializationParams struct {
	// ConnectionParams outlines database connection parameters
	ConnectionParams *helper.DatabaseConnectionParams
	// Logger is the logging utility used by this object
	Logger *zap.Logger
	// MaxConnectionAttempts outlines the maximum connection attempts
	// to initiate against the database
	MaxConnectionAttempts int
	// MaxRetriesPerOperation defines the maximum retries to attempt per failed database
	// connection attempt
	MaxRetriesPerOperation int
	// RetryTimeOut defines the maximum time until a retry operation is observed as a
	// timed out operation
	RetryTimeOut time.Duration
	// RetrySleepInterval defines the amount of time between retry operations
	// that the system sleeps
	RetrySleepInterval time.Duration
}

ConnectionInitializationParams represents connection initialization parameters for the database

type Db

type Db struct {
	// Conn serves as the actual database connection object
	Conn *core_database.DatabaseConn
	// Logger is the logging utility used by this object
	Logger *zap.Logger
	// MaxConnectionAttempts outlines the maximum connection attempts
	// to initiate against the database
	MaxConnectionAttempts int
	// MaxRetriesPerOperation defines the maximum retries to attempt per failed database
	// connection attempt
	MaxRetriesPerOperation int
	// RetryTimeOut defines the maximum time until a retry operation is observed as a
	// timed out operation
	RetryTimeOut time.Duration
	// OperationSleepInterval defines the amount of time between retry operations
	// that the system sleeps
	OperationSleepInterval time.Duration
}

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

func New

New creates a database connection and returns the connection object

func (*Db) AccountActive

func (db *Db) AccountActive(account *models.MerchantAccountORM) bool

func (*Db) ActivateAccount

func (db *Db) ActivateAccount(ctx context.Context, id uint64) (bool, error)

ActivateAccount activates a business account and saves it to the database as long as it exists

the assumption from the context of the database is that all account should have the proper set of parameters in order prior to attempted storage. The client should handle any rpc operations to necessary prior to storage

func (*Db) CheckAccountExistenceStatus

func (db *Db) CheckAccountExistenceStatus(ctx context.Context, id uint64) (bool, error)

CheckAccountExistenceStatus checks if a merchant account exists solely off its Id

func (*Db) CreateMerchantAccount

func (db *Db) CreateMerchantAccount(ctx context.Context, account *models.MerchantAccount) (*models.MerchantAccount, error)

CreateMerchantAccount creates a business account and saves it to the database the assumption from the context of the database is that all account should have the proper set of parameters in order prior to attempted storage. The client should handle any rpc operations to necessary prior to storage

func (*Db) DeactivateMerchantAccount

func (db *Db) DeactivateMerchantAccount(ctx context.Context, id uint64) (bool, error)

DeactivateMerchantAccount deactivates a business account and updates the database

the assumption from the context of the database is that all account should have the proper set of parameters in order prior to attempted storage. The client should handle any rpc operations to necessary prior to storage

func (*Db) FindMerchantAccountByEmail

func (db *Db) FindMerchantAccountByEmail(ctx context.Context, email string) (bool, error)

FindMerchantAccountByEmail finds a merchant account by email

func (*Db) FindMerchantAccountByStripeAccountId

func (db *Db) FindMerchantAccountByStripeAccountId(ctx context.Context, stripeConnectedAccountId string) (*models.MerchantAccount, error)

FindMerchantAccountByStripeAccountId finds a merchant account by stripe id

func (*Db) GetMerchantAccountById

func (db *Db) GetMerchantAccountById(ctx context.Context, id uint64, checkAccountActivationStatus bool) (*models.MerchantAccount, error)

GetMerchantAccountById finds a merchant account by id

func (*Db) SaveAccountRecord

func (db *Db) SaveAccountRecord(ctx context.Context, acct *models.MerchantAccount) error

SaveAccountRecord saves a record in the database

func (*Db) UpdateAccountOnboardStatus

func (db *Db) UpdateAccountOnboardStatus(ctx context.Context, account *models.MerchantAccountORM) error

UpdateAccountOnboardStatus updates the onboarding status of a merchant account

func (*Db) UpdateMerchantAccount

func (db *Db) UpdateMerchantAccount(ctx context.Context, id uint64, account *models.MerchantAccount) (
	*models.MerchantAccount, error)

UpdateMerchantAccount updates a business account and saves it to the database as long as it exists

the assumption from the context of the database is that all account should have the proper set of parameters in order prior to attempted storage. The client should handle any rpc operations to necessary prior to storage

func (*Db) ValidateAccount

func (db *Db) ValidateAccount(ctx context.Context, account *models.MerchantAccountORM) error

ValidateAccount performs various account level validations

func (*Db) ValidateAccountIds

func (db *Db) ValidateAccountIds(ctx context.Context, account *models.MerchantAccountORM) error

ValidateAccountIds validates the existence of various ids associated with the account

func (*Db) ValidateAccountNotNil

func (db *Db) ValidateAccountNotNil(ctx context.Context, account *models.MerchantAccountORM) error

ValidateAccountNotNil ensures the account object is not nil

func (*Db) ValidateAccountParameters

func (db *Db) ValidateAccountParameters(ctx context.Context, account *models.MerchantAccountORM) error

ValidateAccountParameters validates account params.

type Interface

type Interface interface {
	// CreateMerchantAccount creates a merchant account record
	CreateMerchantAccount(ctx context.Context, account *models.MerchantAccount) (*models.MerchantAccount, error)

	// UpdateMerchantAccount updates a merchant account record assuming the record exists
	UpdateMerchantAccount(ctx context.Context, id uint64, account *models.MerchantAccount) (*models.MerchantAccount, error)

	// DeactivateMerchantAccount performs a "soft" delete of the merchant account record
	DeactivateMerchantAccount(ctx context.Context, id uint64) (bool, error)

	// GetMerchantAccountById returns a merchant account record if it exists
	GetMerchantAccountById(ctx context.Context, id uint64, checkAccountActivationStatus bool) (*models.MerchantAccount, error)

	// CheckAccountExistenceStatus asserts a given merchant account exists based on provided merchant account ID
	CheckAccountExistenceStatus(ctx context.Context, id uint64) (bool, error)

	// ActivateAccount activates a merchant account record
	ActivateAccount(ctx context.Context, id uint64) (bool, error)

	// FindMerchantAccountByStripeAccountId attempts to obtain a merchant account record based on the merchant's
	// stripe connected account ID
	FindMerchantAccountByStripeAccountId(ctx context.Context, stripeConnectedAccountId string) (*models.MerchantAccount, error)
}

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

type OperationType

type OperationType string

type TxFunc

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

Jump to

Keyboard shortcuts

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