db

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RepositoryCollection   = "repository"
	SecurityTestCollection = "securityTest"
	AnalysisCollection     = "analysis"
)

Collections names used in MongoDB.

Functions

func Connect

func Connect() error

Connect connects to mongo and returns the session.

Types

type DB

type DB struct {
	Session *mgo.Session
}

DB is the struct that represents mongo session.

var Conn *DB

Conn is the MongoDB connection variable.

func (*DB) Insert

func (db *DB) Insert(obj interface{}, collection string) error

Insert inserts a new document.

func (*DB) Search

func (db *DB) Search(query bson.M, selectors []string, collection string, obj interface{}) error

Search searchs all documents that match the query. If selectors are present, the return will be only the chosen fields.

func (*DB) SearchOne

func (db *DB) SearchOne(query bson.M, selectors []string, collection string, obj interface{}) error

SearchOne searchs for the first element that matchs with the given query.

func (*DB) Update

func (db *DB) Update(query, updateQuery interface{}, collection string) error

Update updates a single document.

func (*DB) UpdateAll

func (db *DB) UpdateAll(query, updateQuery interface{}, collection string) error

UpdateAll updates all documents that match the query.

func (*DB) Upsert

func (db *DB) Upsert(query bson.M, obj interface{}, collection string) (*mgo.ChangeInfo, error)

Upsert inserts a document or update it if it already exists.

type Database

type Database interface {
	Insert(obj interface{}, collection string) error
	Search(query bson.M, selectors []string, collection string, obj interface{}) error
	Update(query bson.M, updateQuery interface{}, collection string) error
	UpdateAll(query, updateQuery bson.M, collection string) error
	Upsert(query bson.M, obj interface{}, collection string) (*mgo.ChangeInfo, error)
	SearchOne(query bson.M, selectors []string, collection string, obj interface{}) error
}

Database is the interface's database.

Jump to

Keyboard shortcuts

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