db

package
v0.0.0-...-af4e4e8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	Client       *mongo.Client
	DatabaseName string
	BasicContext context.Context
}

func NewDB

func NewDB() (*DB, error)

NewDB returns a DB object that is not connected but is optioned correctly

func (*DB) CheckIfCollectionExists

func (db *DB) CheckIfCollectionExists(collectionName string) (bool, error)

CheckIfCollectionExists is used to check if a further DB initialisation is required. Returns true if a Collection with that name exists

func (*DB) ConfigureCollections

func (db *DB) ConfigureCollections() error

ConfigureCollections to be run on startup to check that a number of different Collections exist Creates the collections if not already exist

func (*DB) ConfigureTimeSeriesCollections

func (db *DB) ConfigureTimeSeriesCollections() error

func (*DB) CreateCollection

func (db *DB) CreateCollection(collectionName string, collectionCreationParams ...*options.CreateCollectionOptions) error

CreateCollection creates a collection with a specified name and with creationParameters It does NOT check if the collection already exists and will return an error for sure if it does.

func (*DB) FindAllFromFilter

func (db *DB) FindAllFromFilter(collectionName string, filter bson.M) (*mongo.Cursor, error)

FindAllFromFilter returns a mongo.Cursor that can be iterated over In order to return all the documents you need to have an empty filter

func (*DB) FindOne

func (db *DB) FindOne(collectionName string, filter bson.M) (*mongo.SingleResult, error)

FindOne returns one document from the specified collection Returns a bson.M that needs to be decoded ( bson.M.decode() ) You need to check if the result.Err() is mongo.ErrNoDocuments if it returns Err

func (*DB) FirstStartDBMigrations

func (db *DB) FirstStartDBMigrations() error

func (*DB) InsertMany

func (db *DB) InsertMany(collectionName string, data []interface{}) error

InsertMany inserts many documents into the specified collection Uses bson.M which does NOT care about the order of the json fields and data

func (*DB) InsertOne

func (db *DB) InsertOne(collectionName string, data bson.M) error

InsertOne inserts one document into the specified collection Uses bson.M which does NOT care about the order of the json fields and data

Jump to

Keyboard shortcuts

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