db

package
v0.0.0-...-9abda77 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const AuthDbPool = "auth"
View Source
const (
	// DatabaseNotConnected Error
	DatabaseNotConnected = "Database not Connected"
)

Variables

View Source
var ErrEntityNotFound = errors.New("document not found")
View Source
var ErrMoreThanOneItemDeleted = errors.New("more than one item deleted")

Functions

This section is empty.

Types

type Db

type Db struct {
	IsConnected  bool
	DatabaseName string
	// contains filtered or unexported fields
}

Db gives access to the Mongodb Database

func NewConnection

func NewConnection(ctx context.Context, connectionString string, dataBase string) (db *Db, err error)

NewConnection in Context to the Database

func (*Db) AddFile

func (db *Db) AddFile(ctx context.Context, reference string, p []byte) (*TrackedItem, error)

AddFile adds a File to Mongodbs Gridfs

func (*Db) Close

func (db *Db) Close(ctx context.Context) error

Close the Database Connection

func (*Db) Collection

func (db *Db) Collection(ctx context.Context, collectionName string) (p *Pool, err error)

Collection creates or utilizes a Database subset

func (*Db) ReadFile

func (db *Db) ReadFile(ctx context.Context, reference string) ([]byte, error)

type DbEntity

type DbEntity struct {
	Entity
}

type Entity

type Entity interface {
	AsMap() map[string]interface{}
	GetEntityId() EntityId
	FromMap(map[string]interface{}) error
}

type EntityId

type EntityId string

type Filter

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

func NewFilter

func NewFilter(fieldName string, value interface{}) *Filter

func (*Filter) Filter

func (f *Filter) Filter(fieldName string, value interface{}) *Filter

type Pool

type Pool struct {
	Name string
	// contains filtered or unexported fields
}

Pool is a Subset of Data in the MongoDb

func (*Pool) Add

func (p *Pool) Add(ctx context.Context, entity Entity) (*TrackedItem, error)

func (*Pool) AddM

func (p *Pool) AddM(ctx context.Context, document *bson.M) (item *TrackedItem, err error)

AddM adds a Entity where the Entity is represented by bson.M to the MongoDb

func (*Pool) Delete

func (p *Pool) Delete(ctx context.Context, id EntityId) error

Delete removes a tracked Item form the Database

func (*Pool) DeleteDatabase

func (p *Pool) DeleteDatabase(ctx context.Context) error

DeleteDatabase Delete a given Database by Pool

func (*Pool) Find

func (p *Pool) Find(ctx context.Context, filter Filter) ([]*DbEntity, error)

func (*Pool) Get

func (p *Pool) Get(ctx context.Context, search *Filter) (*DbEntity, error)

func (*Pool) Update

func (p *Pool) Update(ctx context.Context, filter *bson.M, fields map[string]interface{}) (int64, error)

Update updates all Itemes by the filter from the given map

type TrackedItem

type TrackedItem struct {
	InsertedID primitive.ObjectID
	Collection string
	IsFile     bool
}

TrackedItem is the Item Returned from Database as a Tracked Item

Jump to

Keyboard shortcuts

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