database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package database provides functions to connect and manipulate database data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoHelper

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

func NewMongoHelper

func NewMongoHelper(dbUser string, dbPassword string, dbHost string, dbPort string, database string) *MongoHelper

func (*MongoHelper) FindDocument

func (m *MongoHelper) FindDocument(collectionName string, id string) (record interface{}, err error)

FindDocument returns a record that satisfies the provided conditions. It returns nil if the record is unavailable in the collection.

func (*MongoHelper) GetCollection

func (m *MongoHelper) GetCollection(client *mongo.Client, collectionName string) (*mongo.Collection, error)

GetCollection returns collection reference

func (*MongoHelper) GetDatabase

func (m *MongoHelper) GetDatabase(client *mongo.Client) (*mongo.Database, error)

GetDatabase returns database reference

func (*MongoHelper) GetSession

func (m *MongoHelper) GetSession() (*mongo.Client, error)

GetSession creates a db session and returns its reference.

func (*MongoHelper) GetaRecord

func (m *MongoHelper) GetaRecord(collectionName string, condition bson.M) (record interface{}, err error)

GetaRecord returns a record that satisfies the provided conditions. It returns nil if the record is unavailable in the collection.

func (*MongoHelper) InsertDocument

func (m *MongoHelper) InsertDocument(collectionName string, entry interface{}) (interface{}, error)

InsertDocument inserts an entry in the specified collection name using the provided db session

func (*MongoHelper) IsExistingDocument

func (m *MongoHelper) IsExistingDocument(collectionName string, condition bson.M) (found bool, err error)

IsExistingDocument tests the existence of a record with the provided conditions. It returns true if the record is available in the collection.

func (*MongoHelper) RemoveCollection

func (m *MongoHelper) RemoveCollection(collectionName string) (err error)

RemoveCollection deletes the collection from the database. It returns nil if the collection successfully deleted.

func (*MongoHelper) UpdateDocument

func (m *MongoHelper) UpdateDocument(collectionName string, id string, entry interface{}) error

UpdateDocument updates an entry in the specified collection name

Jump to

Keyboard shortcuts

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