mongodb

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connection

func Connection(ctx context.Context, cfg *Configuration) (*mongowrapper.WrappedClient, error)

Connection provides Wire provider for a MongoDB database connection

func ConvertSortParameters

func ConvertSortParameters(params db.SortParameters) []string

ConvertSortParameters to sql query string

func Transaction

func Transaction(ctx context.Context, client *mongowrapper.WrappedClient, fn TransactionFunc) error

Transaction runs the transactionfunc in a transaction

Types

type Configuration

type Configuration struct {
	AutoMigrate      bool
	ConnectionString string
	DatabaseName     string
	Username         string
	Password         string
}

Configuration repesents database connection configuration

type Default

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

Default contains the basic implementation of the MongoCRUD interface

func NewCRUDTable

func NewCRUDTable(session *mongowrapper.WrappedClient, db, table string) *Default

NewCRUDTable sets up a new Default struct

func (*Default) Delete

func (d *Default) Delete(ctx context.Context, id interface{}) error

Delete deletes a resource with specified ID

func (*Default) DeleteAll

func (d *Default) DeleteAll(ctx context.Context, pred interface{}) error

DeleteAll deletes resources that match the passed filter

func (*Default) Find

func (d *Default) Find(ctx context.Context, id interface{}, value interface{}) error

Find searches for a resource in the database and then returns a cursor

func (*Default) FindBy

func (d *Default) FindBy(ctx context.Context, key string, value interface{}, results interface{}) error

FindBy is an utility for fetching values if they are stored in a key-value manenr.

func (*Default) FindByAndCount

func (d *Default) FindByAndCount(ctx context.Context, key string, value interface{}) (int64, error)

FindByAndCount returns the number of elements that match the filter

func (*Default) FindByAndFetch

func (d *Default) FindByAndFetch(ctx context.Context, key string, value interface{}, results interface{}) error

FindByAndFetch retrieves a value by key and then fills results with the result.

func (*Default) FindFetchOne

func (d *Default) FindFetchOne(ctx context.Context, id string, value interface{}) error

FindFetchOne searches for a resource and then unmarshals the first row into value

func (*Default) FindOneBy

func (d *Default) FindOneBy(ctx context.Context, key string, value interface{}, result interface{}) error

FindOneBy is an utility for fetching values if they are stored in a key-value manenr.

func (*Default) GetDBName

func (d *Default) GetDBName() string

GetDBName returns database's name

func (*Default) GetSession

func (d *Default) GetSession() interface{}

GetSession returns the current session

func (*Default) GetTable

func (d *Default) GetTable() interface{}

GetTable returns the table as a mgo.Collection

func (*Default) GetTableName

func (d *Default) GetTableName() string

GetTableName returns table's name

func (*Default) Insert

func (d *Default) Insert(ctx context.Context, data interface{}) error

Insert inserts a document into the database

func (*Default) InsertOrUpdate

func (d *Default) InsertOrUpdate(ctx context.Context, id interface{}, data interface{}) error

InsertOrUpdate inserts or update document if exists

func (*Default) List

func (d *Default) List(ctx context.Context, results interface{}, sortParams *db.SortParameters, pagination *db.Pagination) error

List all entities from the database

func (*Default) Search

func (d *Default) Search(ctx context.Context, results interface{}, filter interface{}, sortParams *db.SortParameters, pagination *db.Pagination) error

Search all entities from the database

func (*Default) Update

func (d *Default) Update(ctx context.Context, selector interface{}, data interface{}) error

Update performs an update on an existing resource according to passed data

func (*Default) UpdateID

func (d *Default) UpdateID(ctx context.Context, id interface{}, data interface{}) error

UpdateID performs an update on an existing resource with ID that equals the id argument

func (*Default) Where

func (d *Default) Where(ctx context.Context, filter interface{}, results interface{}) error

Where allows filtering with multiple fields

func (*Default) WhereAndFetchLimit

func (d *Default) WhereAndFetchLimit(ctx context.Context, filter interface{}, paginator *db.Pagination, results interface{}) error

WhereAndFetchLimit filters with multiple fields and then fills results with all found resources

func (*Default) WhereAndFetchOne

func (d *Default) WhereAndFetchOne(ctx context.Context, filter interface{}, result interface{}) error

WhereAndFetchOne filters with multiple fields and then fills result with the first found resource

func (*Default) WhereCount

func (d *Default) WhereCount(ctx context.Context, filter interface{}) (int64, error)

WhereCount allows counting with multiple fields

type TransactionFunc

type TransactionFunc func() error

TransactionFunc is the transaction handler closure contract

Jump to

Keyboard shortcuts

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