db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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