mongodb

package
v0.0.0-...-222ed67 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const CollectionName = "Subscriptions"

CollectionName is the name of Subscription collection

View Source
const DocumentLimitsPerQuery = 1000

DocumentLimitsPerQuery limits query result to a certain number of documents

Variables

This section is empty.

Functions

func ToDomain

func ToDomain(s *Subscription) *domain.Subscription

ToDomain converts MongoDB document representation of Subscription to domain model

func ToDomainSlice

func ToDomainSlice(subs []*Subscription) []*domain.Subscription

ToDomainSlice converts slice of MongoDB documents to slice of domain models

Types

type Filter

type Filter struct {
	Condition string `bson:"condition" json:"condition"`
	IsMust    bool   `bson:"is_must" json:"is_must"`
	Type      string `bson:"type" json:"type"`
}

Filter represents a document in MongoDB corresponding to domain.Filter

type Subscription

type Subscription struct {
	ID                  string   `bson:"_id" json:"_id"`
	UserID              string   `bson:"user_id" json:"user_id"`
	Currency            string   `bson:"currency" json:"currency"`
	CurrencyDecimal     string   `bson:"currency_decimal" json:"currency_decimal"`
	Account             string   `bson:"account" json:"account"`
	BlockHeight         uint64   `bson:"block_height" json:"block_height"`
	TotalReceived       string   `bson:"total_received" json:"total_received"`
	TotalSpent          string   `bson:"total_spent" json:"total_spent"`
	StartingBlockHeight uint64   `bson:"starting_block_height" json:"starting_block_height"`
	Filters             []Filter `bson:"filters" json:"filters"`
}

Subscription represents a document in MongoDB corresponding to domain.Subscription

func FromDomain

func FromDomain(s *domain.Subscription) *Subscription

FromDomain converts domain.Subscription model to a MongoDB document representation

type SubscriptionRepository

type SubscriptionRepository struct {
	// contains filtered or unexported fields
}

SubscriptionRepository is MongoDB implementation of SubscriptionRepository

func NewSubscriptionRepository

func NewSubscriptionRepository() *SubscriptionRepository

NewSubscriptionRepository creates a new instance of SubscriptionRepository

func (*SubscriptionRepository) Begin

func (r *SubscriptionRepository) Begin() error

Begin starts a new session for ACID operation

func (*SubscriptionRepository) Connect

func (r *SubscriptionRepository) Connect(uri string, databaseName string) error

Connect creates a connection to the given mongodb instance and the database

func (*SubscriptionRepository) Disconnect

func (r *SubscriptionRepository) Disconnect() error

Disconnect closes connection with the connected mongodb instance

func (*SubscriptionRepository) Fail

func (r *SubscriptionRepository) Fail()

Fail rollbacks to the state before this change. Notice that due to the fact that every operation is wrapped in MongoDB Callback-API (https://docs.mongodb.com/manual/core/transactions-in-applications/#callback-api) Here, just close the session and release the locked mutex

func (*SubscriptionRepository) Get

Get returns the subscription for the given subscription id

func (*SubscriptionRepository) GetAllForCurrency

func (r *SubscriptionRepository) GetAllForCurrency(currencySymbol string, updatedBefore uint64) ([]*domain.Subscription, error)

GetAllForCurrency returns all subscriptions for the given currency

func (*SubscriptionRepository) GetAllForUser

func (r *SubscriptionRepository) GetAllForUser(userID string) ([]*domain.Subscription, error)

GetAllForUser returns all subscriptions for the given user id

func (*SubscriptionRepository) NextIdentity

func (r *SubscriptionRepository) NextIdentity(userID string) string

NextIdentity returns the next available identity

func (*SubscriptionRepository) Remove

Remove removes the given subscription from the persistance

func (*SubscriptionRepository) Save

Save persists/updates the given subscription

func (*SubscriptionRepository) Size

func (r *SubscriptionRepository) Size() int64

Size returns the total number of subscriptions persited in the repository

func (*SubscriptionRepository) Success

func (r *SubscriptionRepository) Success()

Success finalizes ACID operation Notice that due to the fact that every operation is wrapped in MongoDB Callback-API (https://docs.mongodb.com/manual/core/transactions-in-applications/#callback-api) Here, just close the session and release the locked mutex

Jump to

Keyboard shortcuts

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