mongo

package module
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

README

Neuron Logo

Neuron Mongo Go Report Card GoDoc Build Status License

Neuron Mongo is the neuron-core mongodb repository implementation. It is based on the official mongo golang driver: github.com/mongodb/mongo-go-driver.

To use this package, import it in your code and set model's mapped repositories with the mongo factory driver name.

What is Neuron-Mongo

Neuron-Mongo is the MongoDB ORM Repository driver for the github.com/neuronlabs/neuron-core.

Installation

go get -u github.com/neuronlabs/neuron-mongo

Neuron-Mongo is the extension for the Neuron-Core requires github.com/neuronlabs/neuron-core root package.

Docs

Documentation

Index

Constants

View Source
const (
	ReplicaSetHostsKey = "replica_set_hosts"
	ApplicationNameKey = "application_name"
)

config.Repository.Options keys constants

View Source
const DirectConnectOption = "connect-direct"

DirectConnectOption is the option to set direct connect.

Variables

This section is empty.

Functions

func RegisterFilterOperator

func RegisterFilterOperator(o *filters.Operator)

RegisterFilterOperator registers operator with the BSONizer function.

func StringDecoderValue

func StringDecoderValue(dctx bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) (err error)

StringDecoderValue is the value decoder for the string fields.

Types

type Config

type Config struct {
	*config.Repository
	// Hosts are the replica set hosts
	Hosts []string
	// ReplicaSetName is the name of the replica set
	ReplicaSetName string
	// Direct sets direct connection.
	Direct bool
	// ApplicationName is the name used in the mongodb logs for the specific client
	ApplicationName string
	// Options are the client options
	Options *options.ClientOptions
	// contains filtered or unexported fields
}

Config is the mongo db repository configuration struct.

func NewConfig

func NewConfig(cfgRepo *config.Repository) (*Config, error)

NewConfig creates new repository config.

func (*Config) Connection

func (c *Config) Connection() (*mongo.Client, error)

Connection creates new mongo client connection.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the mongo config.

type Factory

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

Factory is the MongoDB - neuron repository.Factory.

func New

func New() *Factory

New creates new mongo.Factory.

func (*Factory) Close

func (f *Factory) Close(ctx context.Context, done chan<- interface{})

Close closes the repository instances.

func (*Factory) DriverName added in v0.2.2

func (f *Factory) DriverName() string

DriverName implements repository.Repository interface.

func (*Factory) New

New create new Mongo repository for the provided ModelStruct.

type Repository

type Repository struct {
	// Client is the mongodb connection client.
	Client *mongo.Client
	// Config contains all the connection configurations.
	Config *Config
	// contains filtered or unexported fields
}

Repository is the MongoDB - Neuron repository.Repository.

func (*Repository) Begin

func (r *Repository) Begin(ctx context.Context, s *query.Scope) error

Begin implements query.Transactioner interface, Begin method.

func (*Repository) Close

func (r *Repository) Close(ctx context.Context) error

Close closes the repository active connections.

func (*Repository) Commit

func (r *Repository) Commit(ctx context.Context, s *query.Scope) error

Commit implements query.Transactioner interface, Commit method.

func (*Repository) Count added in v0.8.1

func (r *Repository) Count(ctx context.Context, s *query.Scope) (int64, error)

Count implements query.Counter interface.

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, s *query.Scope) error

Create uses the mongo repository to create the query scope value. Implements query.Creator interface.

func (*Repository) CreateMany

func (r *Repository) CreateMany(ctx context.Context, s *query.Scope) error

CreateMany inserts multiple instances of given scope values Implements query.ManyCreator interface

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, s *query.Scope) error

Delete uses the mongo repository to create the query scope value. Implements query.Deleter interface.

func (*Repository) FactoryName added in v0.6.1

func (r *Repository) FactoryName() string

FactoryName implements repository.Repository interface.

func (*Repository) Get

func (r *Repository) Get(ctx context.Context, s *query.Scope) error

Get uses the mongo repository to get the query scope value from the mongo database. Implements query.Getter interface.

func (*Repository) List

func (r *Repository) List(ctx context.Context, s *query.Scope) error

List uses the mongo repository to create the query scope value. Implements query.Lister interface.

func (*Repository) Patch

func (r *Repository) Patch(ctx context.Context, s *query.Scope) error

Patch uses the mongo repository to create the query scope value. Implements query.Patcher interface.

func (*Repository) Rollback

func (r *Repository) Rollback(ctx context.Context, s *query.Scope) error

Rollback implements query.Transactioner interface, Rollback method.

Directories

Path Synopsis
Package tests contains test files for the neuron mongo repository
Package tests contains test files for the neuron mongo repository

Jump to

Keyboard shortcuts

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