database

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateIndexOnTransactionField

func CreateIndexOnTransactionField(ctx context.Context, indexData []mongo.IndexModel) error

CreateIndexOnTransactionField creates a B-Tree index on the specified field in the transaction collection.

func DeleteAccount

func DeleteAccount(ctx context.Context, accountID string) error

DeleteAccount deletes an account in the database.

func DeleteTransaction

func DeleteTransaction(ctx context.Context, transactionID primitive.ObjectID) error

DeleteTransaction deletes a transaction from the database.

func GetAccountBalances

func GetAccountBalances(ctx context.Context) (map[string]float64, error)

GetAccountBalances provides a map of account IDs to their balance.

func GetTransaction

func GetTransaction(ctx context.Context, transactionID primitive.ObjectID) (*models.TransactionDTO, error)

GetTransaction returns the transaction record matching the provided ID.

func InsertAccount

func InsertAccount(ctx context.Context, account *models.AccountDTO) error

InsertAccount creates a new account in the database.

func InsertTransaction

func InsertTransaction(ctx context.Context, transaction *models.TransactionDTO) (interface{}, error)

InsertTransaction creates a new transaction in the database. It returns the ID of the inserted document as well as the error if any.

func IsAccountExists

func IsAccountExists(ctx context.Context, accountID string) (bool, error)

IsAccountExists returns true if the account with the provided ID exists.

func IsAccountUsed

func IsAccountUsed(ctx context.Context, accountID string) (bool, error)

IsAccountUsed returns true if even a single transaction is using the provided account, otherwise it returns false.

func ListAccounts

func ListAccounts(ctx context.Context) ([]*models.AccountDTO, error)

ListAccounts provides a list of all accounts.

func ListTransactions

func ListTransactions(ctx context.Context, params *ListTransactionsParams) ([]*models.TransactionDTO, int, error)

ListTransactions lists all the transactions that match the provided filter, pagination and sort params.

func UpdateAccount

func UpdateAccount(ctx context.Context, accountID string, updates map[string]interface{}) error

UpdateAccount updates an account in the database.

func UpdateTransaction

func UpdateTransaction(ctx context.Context, transactionID primitive.ObjectID, updates map[string]interface{}) error

UpdateTransaction updates a transaction in the database.

Types

type ListTransactionsParams

type ListTransactionsParams struct {
	// Filter is the search filter for the transactions.
	Filter map[string]interface{}
	// RequiredFields is the list of fields to be included in the response.
	RequiredFields []string
	// PaginationLimit is the max amount of transactions in the response.
	PaginationLimit int
	// PaginationSkip is the initial offset of the list.
	PaginationSkip int
	// SortField is the name of the field by which the transactions will be sorted.
	SortField string
	// SortOrder is the order of sorting.
	SortOrder int
	// ExcludeCount is a flag to control whether the total count of the transaction should also be calculated or not.
	ExcludeCount bool
}

ListTransactionsParams is the schema of params required by the ListTransactions operation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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