dbutil

package
v0.0.0-...-1f26eb9 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddArchiveToDB

func AddArchiveToDB(ctx context.Context, client *mongo.Client, dbName string, archive MetaArchive)

func BucketMapfromSlice

func BucketMapfromSlice(slice []SourceBucket) map[string]SourceBucket

func CloseMDB

func CloseMDB(client *mongo.Client, ctx context.Context, cancel context.CancelFunc)

CloseMDB is a user defined method to close resources. This method closes mongoDB connection and cancel context.

func ConnectToMDB

func ConnectToMDB(uri string) (*mongo.Client, context.Context, context.CancelFunc, error)

ConnectToMDB is a user defined method that returns mongo.Client, context.Context, context.CancelFunc and error. mongo.Client will be used for further database operation. context.Context will be used set deadlines for process. context.CancelFunc will be used to cancel context and resource associtated with it.

func InsertMany

func InsertMany(ctx context.Context, client *mongo.Client, dbName string, col string,
	docs []interface{}) (*mongo.InsertManyResult, error)

InsertMany is a user defined method, used to insert documents into collection returns result of InsertMany and error if any.

func InsertOne

func InsertOne(ctx context.Context, client *mongo.Client, dbName string, col string,
	doc interface{}) (*mongo.InsertOneResult, error)

InsertOne is a user defined method, used to insert documents into collection returns result of InsertOne and error if any.

func LoadArchiveIDs

func LoadArchiveIDs(ctx context.Context, client *mongo.Client, dbName string) (datastructs.Set, error)

LoadArchiveIDs retrieves a list of archiveIDs from the database

func PingMDB

func PingMDB(ctx context.Context, client *mongo.Client) error

PingMDB is a user defined method that accepts mongo.Client and context.Context This method used to ping the mongoDB, return error if any.

func UpdateArchiveIDs

func UpdateArchiveIDs(ctx context.Context, client *mongo.Client, dbName string, update interface{}) (*mongo.UpdateResult, error)

UpdateArchiveIDs updates the list of archiveIDs in the DB

func UpdateFilesOfArchive

func UpdateFilesOfArchive(ctx context.Context, client *mongo.Client, dbName string, id string, update interface{}) (*mongo.UpdateResult, error)

UpdateFilesOfArchive accepts client, context, database, collection, filter and update filter and update is of type interface this method returns UpdateResult and an error if any.

func UpdateSourceBuckets

func UpdateSourceBuckets(ctx context.Context, client *mongo.Client, dbName string, update interface{}) (*mongo.UpdateResult, error)

UpdateSourceBuckets updates the list of archiveIDs in the DB

Types

type MetaArchive

type MetaArchive struct {
	ID          string          `json:"id"`
	Files       datastructs.Set `json:"files"`
	TimeCreated string          `json:"timeCreated"`
	TimeUpdated string          `json:"timeUpdated"`
	Status      string          `json:"status"`
	Source      string          `json:"source"`
}

MetaArchive is the blueprint for the zip archives that will be created once the user initiates the download process. Files is implemented as a set in order to avoid duplicate files within a metaArchive

func FindArchiveInDB

func FindArchiveInDB(ctx context.Context, client *mongo.Client, dbName, id string) (MetaArchive, error)

FindArchiveInDB retrieves an archive from the MongoDB

func NewMetaArchiveInDB

func NewMetaArchiveInDB(ctx context.Context, client *mongo.Client, dbName string, id string, files []string) MetaArchive

func (MetaArchive) ToBSON

func (a MetaArchive) ToBSON() bson.D

ToBSON converts the meta archive to binary JSON format

type MetaArchiveRaw

type MetaArchiveRaw struct {
	ID          string   `json:"id"`
	Files       []string `json:"files"`
	TimeCreated string   `json:"timeCreated"`
	TimeUpdated string   `json:"timeUpdated"`
	Status      string   `json:"status"`
	Source      string   `json:"source"`
}
type metaArchive struct {
	ID    string `json:"id"`
	Files set    `json:"files"`
}

type SourceBucket

type SourceBucket struct {
	BucketID       string `json:"ID"`
	BucketURL      string
	BucketName     string
	BucketPrefixes []string
	BucketOrigin   string
	Description    string
	Owner          string
}

func LoadSourceBuckets

func LoadSourceBuckets(ctx context.Context, client *mongo.Client, dbName string) ([]SourceBucket, error)

LoadSourceBuckets retrieves a list of archiveIDs from the db

func (SourceBucket) ToBSON

func (sb SourceBucket) ToBSON() bson.D

Jump to

Keyboard shortcuts

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