mongostorage

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ObjectID

func ObjectID[T ~string](domainID T) primitive.ObjectID

ObjectID will convert a string-compatible type to primitive.ObjectID

Types

type RetryingStorage

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

RetryingStorage wraps StorageReaderWriter for read side

func NewRetry

func NewRetry(upstream StorageReaderWriter, logger *zap.Logger) *RetryingStorage

NewRetry creates new mongostorage with retries

func (*RetryingStorage) Delete

func (s *RetryingStorage) Delete(ctx context.Context, collection string, docID primitive.ObjectID) (deletedCount int64, err error)

Delete deletes document in the database.

func (*RetryingStorage) DeleteMany

func (s *RetryingStorage) DeleteMany(ctx context.Context, collection string, filter interface{}) (deletedCount int64, err error)

DeleteMany deletes filtered documents in the database.

func (*RetryingStorage) FindAll

func (s *RetryingStorage) FindAll(ctx context.Context, collection string, filter interface{}, dest interface{}) (err error)

FindAll returns all rows matching filter into destination.

func (*RetryingStorage) FindMany

func (s *RetryingStorage) FindMany(ctx context.Context, collection string, filter interface{}, limit, offset uint64, sort string, dest interface{}) (total uint64, err error)

FindMany returns rows into destination.

func (*RetryingStorage) FindOne

func (s *RetryingStorage) FindOne(ctx context.Context, collection string, filter interface{}, dest interface{}) (err error)

FindOne returns a row into destination.

func (*RetryingStorage) GetDatabaseName

func (s *RetryingStorage) GetDatabaseName() string

GetDatabaseName returns the name of the current database.

func (*RetryingStorage) Insert

func (s *RetryingStorage) Insert(ctx context.Context, collection string, document interface{}) error

Insert makes insert into database.

func (*RetryingStorage) RunInTransaction

func (s *RetryingStorage) RunInTransaction(ctx context.Context, fn func(context.Context) error) error

RunInTransaction encapsulates the function that needs to run in a transaction.

func (*RetryingStorage) Update

func (s *RetryingStorage) Update(ctx context.Context, collection string, docID primitive.ObjectID, update interface{}) (modifiedCount int64, err error)

Update updates documents in the database.

func (*RetryingStorage) Upsert

func (s *RetryingStorage) Upsert(ctx context.Context, collection string, docID interface{}, update interface{}) (upsertedCount int64, err error)

Upsert updates or inserts document in the database.

type Storage

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

Storage manages query builders and database requests.

func (*Storage) Delete

func (s *Storage) Delete(ctx context.Context, collection string, docID primitive.ObjectID) (deletedCount int64, err error)

Delete deletes document in the database.

func (*Storage) DeleteMany

func (s *Storage) DeleteMany(ctx context.Context, collection string, filter interface{}) (deletedCount int64, err error)

DeleteMany deletes filtered documents in the database.

func (*Storage) FindAll

func (s *Storage) FindAll(ctx context.Context, collection string, filter interface{}, dest interface{}) (err error)

FindAll returns all rows matching filter into destination.

func (*Storage) FindMany

func (s *Storage) FindMany(
	ctx context.Context,
	collection string,
	filter interface{},
	limit, offset uint64,
	sort string,
	dest interface{},
) (total uint64, err error)

FindMany returns rows into destination.

func (*Storage) FindOne

func (s *Storage) FindOne(ctx context.Context, collection string, filter interface{}, dest interface{}) (err error)

FindOne returns a row into destination.

func (*Storage) GetDatabaseName

func (s *Storage) GetDatabaseName() string

GetDatabaseName returns the name of the current database

func (*Storage) Insert

func (s *Storage) Insert(ctx context.Context, collection string, document interface{}) error

Insert makes insert into database.

func (*Storage) RunInTransaction

func (s *Storage) RunInTransaction(ctx context.Context, fn func(context.Context) error) error

RunInTransaction encapsulates the function that needs to run in a transaction.

func (*Storage) Update

func (s *Storage) Update(ctx context.Context, collection string, docID primitive.ObjectID, update interface{}) (modifiedCount int64, err error)

Update updates documents in the database.

func (*Storage) Upsert

func (s *Storage) Upsert(ctx context.Context, collection string, docID interface{}, update interface{}) (upsertedCount int64, err error)

Upsert updates or inserts document in the database.

type StorageReader

type StorageReader interface {
	FindOne(ctx context.Context, collection string, filter interface{}, dest interface{}) (err error)
	FindAll(ctx context.Context, collection string, filter interface{}, dest interface{}) (err error)
	FindMany(
		ctx context.Context,
		collection string,
		filter interface{},
		limit, offset uint64,
		sort string,
		dest interface{},
	) (total uint64, err error)
}

StorageReader describes interface for read operations for mongostorage

type StorageReaderWriter

type StorageReaderWriter interface {
	StorageReader
	StorageWriter

	GetDatabaseName() string
}

StorageReaderWriter describes interface for both read and write operations for mongostorage

func New

New initializes database mongostorage.

type StorageWriter

type StorageWriter interface {
	RunInTransaction(ctx context.Context, fn func(context.Context) error) error
	Insert(ctx context.Context, collection string, document interface{}) error
	Update(ctx context.Context, collection string, docID primitive.ObjectID, update interface{}) (modifiedCount int64, err error)
	Upsert(ctx context.Context, collection string, docID interface{}, update interface{}) (upsertedCount int64, err error)
	Delete(ctx context.Context, collection string, docID primitive.ObjectID) (deletedCount int64, err error)
	DeleteMany(ctx context.Context, collection string, filter interface{}) (deletedCount int64, err error)
}

StorageWriter describes interface for write operations for mongostorage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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