mongo

package
v4.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: MIT Imports: 16 Imported by: 2

README

MongoDB adapter for upper.io/db

Please read the full docs, acknowledgements and examples at https://github.com/upper/db/wrappers/mongo.

Documentation

Overview

Package mongo wraps the gopkg.in/mgo.v2 MongoDB driver. See https://github.com/upper/db/adapter/mongo for documentation, particularities and usage examples.

Index

Constants

View Source
const Adapter = `mongo`

Adapter holds the name of the mongodb adapter.

Variables

This section is empty.

Functions

func Open

func Open(settings db.ConnectionURL) (db.Session, error)

Open stablishes a new connection to a SQL server.

Types

type Collection

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

Collection represents a mongodb collection.

func (*Collection) Count

func (col *Collection) Count() (uint64, error)

func (*Collection) Exists

func (col *Collection) Exists() (bool, error)

Exists returns true if the collection exists.

func (*Collection) Find

func (col *Collection) Find(terms ...interface{}) db.Result

Find creates a result set with the given conditions.

func (*Collection) Insert

func (col *Collection) Insert(item interface{}) (*db.InsertResult, error)

Insert inserts an item (map or struct) into the collection.

func (*Collection) InsertReturning

func (col *Collection) InsertReturning(item interface{}) error

func (*Collection) Name

func (col *Collection) Name() string

Name returns the name of the table or tables that form the collection.

func (*Collection) Session

func (col *Collection) Session() db.Session

func (*Collection) Truncate

func (col *Collection) Truncate() error

Truncate deletes all rows from the table.

func (*Collection) UpdateReturning

func (col *Collection) UpdateReturning(item interface{}) error

type ConnectionURL

type ConnectionURL struct {
	User     string
	Password string
	Host     string
	Database string
	Options  map[string]string
}

ConnectionURL implements a MongoDB connection struct.

func ParseURL

func ParseURL(s string) (conn ConnectionURL, err error)

ParseURL parses s into a ConnectionURL struct.

func (ConnectionURL) String

func (c ConnectionURL) String() (s string)

type Source

type Source struct {
	db.Settings
	// contains filtered or unexported fields
}

Source represents a MongoDB database.

func (*Source) Clone

func (s *Source) Clone() (db.Session, error)

Clone returns a cloned db.Session session.

func (*Source) Close

func (s *Source) Close() error

Close terminates the current database session.

func (*Source) Collection

func (s *Source) Collection(name string) db.Collection

Collection returns a collection by name.

func (*Source) Collections

func (s *Source) Collections() (cols []db.Collection, err error)

Collections returns a list of non-system tables from the database.

func (*Source) ConnectionURL

func (s *Source) ConnectionURL() db.ConnectionURL

func (*Source) Driver

func (s *Source) Driver() interface{}

Driver returns the underlying *mgo.Session instance.

func (*Source) Get

func (s *Source) Get(db.Model, interface{}) error

func (*Source) Item

func (s *Source) Item(m db.Model) db.Item

func (*Source) Name

func (s *Source) Name() string

Name returns the name of the database.

func (*Source) NewTransaction

func (s *Source) NewTransaction() (db.Tx, error)

NewTransaction should support transactions, but it doesn't as MongoDB currently does not support them.

func (*Source) Open

func (s *Source) Open(connURL db.ConnectionURL) error

Open attempts to connect to the database.

func (*Source) Ping

func (s *Source) Ping() error

Ping checks whether a connection to the database is still alive by pinging it, establishing a connection if necessary.

func (*Source) Reset

func (s *Source) Reset()

func (*Source) Save

func (s *Source) Save(db.Model) error

func (*Source) SetConnMaxLifetime

func (s *Source) SetConnMaxLifetime(time.Duration)

SetConnMaxLifetime is not supported.

func (*Source) SetMaxIdleConns

func (s *Source) SetMaxIdleConns(int)

SetMaxIdleConns is not supported.

func (*Source) SetMaxOpenConns

func (s *Source) SetMaxOpenConns(int)

SetMaxOpenConns is not supported.

Jump to

Keyboard shortcuts

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