Documentation ¶
Overview ¶
Package database provides functions to connect and manipulate database data.
Index ¶
- type MongoHelper
- func (m *MongoHelper) FindDocument(collectionName string, id string) (record interface{}, err error)
- func (m *MongoHelper) GetCollection(client *mongo.Client, collectionName string) (*mongo.Collection, error)
- func (m *MongoHelper) GetDatabase(client *mongo.Client) (*mongo.Database, error)
- func (m *MongoHelper) GetSession() (*mongo.Client, error)
- func (m *MongoHelper) GetaRecord(collectionName string, condition bson.M) (record interface{}, err error)
- func (m *MongoHelper) InsertDocument(collectionName string, entry interface{}) (interface{}, error)
- func (m *MongoHelper) IsExistingDocument(collectionName string, condition bson.M) (found bool, err error)
- func (m *MongoHelper) RemoveCollection(collectionName string) (err error)
- func (m *MongoHelper) UpdateDocument(collectionName string, id string, entry interface{}) error
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 (*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 ¶
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