db

package
v0.0.0-...-20fe154 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatabaseNotInitialized = errors.New("Database not initialized")
)

Errors

Functions

func NewXID

func NewXID() xid.ID

NewXID returns a new secure ID using the rs/xid librady

Types

type Mongo

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

Mongo is the struct used to interact with a MongoDB database from backd apis

func NewMongo

func NewMongo(ctx context.Context, mongoURL string) (*Mongo, error)

NewMongo returns a DB struct to interact with MongoDB

func (*Mongo) Can

func (db *Mongo) Can(ctx context.Context, session *pbsessions.Session, isDomain bool, database, collection, id string, perm backd.Permission) bool

Can validates the ability to make something by an user

func (*Mongo) Client

func (db *Mongo) Client() *mongo.Client

Client is a direct access to the Client struct

func (*Mongo) Count

func (db *Mongo) Count(ctx context.Context, database, collection string, query map[string]interface{}) (int64, error)

Count returns the number of ocurrencies returnd from the database using that query

func (*Mongo) CreateApplicationDatabase

func (db *Mongo) CreateApplicationDatabase(ctx context.Context, name string) (err error)

CreateApplicationDatabase creates the required collection for an application to be usable

func (*Mongo) CreateBackdDatabases

func (db *Mongo) CreateBackdDatabases(ctx context.Context) (err error)

CreateBackdDatabases is called on bootstrap to create

func (*Mongo) CreateCollection

func (db *Mongo) CreateCollection(ctx context.Context, database, collection string, validator map[string]interface{}, indexes []structs.Index) (err error)

CreateCollection creates a collection and its indexes on the required database

adding the validation if required

func (*Mongo) CreateDomainDatabase

func (db *Mongo) CreateDomainDatabase(ctx context.Context, name string) (err error)

CreateDomainDatabase creates the required collections on the domain to be usable

func (*Mongo) CreateIndex

func (db *Mongo) CreateIndex(ctx context.Context, database, collection string, keys map[string]interface{}, unique bool) (err error)

CreateIndex creates required indexes with some default settings that seems to be enough for our needs

func (*Mongo) Delete

func (db *Mongo) Delete(ctx context.Context, database, collection string, selector map[string]interface{}) (count int64, err error)

Delete deletes from the collection the referenced object

func (*Mongo) DeleteByID

func (db *Mongo) DeleteByID(ctx context.Context, database, collection, id string) (count int64, err error)

DeleteByID deletes from the collection the referenced object using an ObjectID passed as string

func (*Mongo) DeleteByIDRBAC

func (db *Mongo) DeleteByIDRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, database, collection, id string) (int64, error)

DeleteByIDRBAC deletes from the item from the collection if user has permission for it

func (*Mongo) DeleteByQueryRBAC

func (db *Mongo) DeleteByQueryRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, database, collection string, query map[string]interface{}) (int64, error)

DeleteByQueryRBAC deletes from the item from the collection if user has permission for it

func (*Mongo) GetMany

func (db *Mongo) GetMany(ctx context.Context, database, collection string, query interface{}, sort map[string]interface{}, this interface{}, skip, limit int64) (err error)

GetMany returns all records that meets the desired filter,

skip and limit must be passed to limit the number of results

func (*Mongo) GetManyRBAC

func (db *Mongo) GetManyRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, perm backd.Permission, database, collection string, query, sort map[string]interface{}, this interface{}, skip, limit int64) error

GetManyRBAC returns all records that meets RBAC and the desired filter,

skip and limit must be passed to limit the number of results

func (*Mongo) GetOne

func (db *Mongo) GetOne(ctx context.Context, database, collection string, query, this interface{}) error

GetOne returns one object by query

func (*Mongo) GetOneByID

func (db *Mongo) GetOneByID(ctx context.Context, database, collection, id string, this interface{}) error

GetOneByID returns one object by ID

func (*Mongo) GetOneByIDRBAC

func (db *Mongo) GetOneByIDRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, perm backd.Permission, database, collection, id string) (map[string]interface{}, error)

GetOneByIDRBAC returns one object by ID

func (*Mongo) GetOneByIDRBACInterface

func (db *Mongo) GetOneByIDRBACInterface(ctx context.Context, session *pbsessions.Session, isDomain bool, perm backd.Permission, database, collection, id string, this interface{}) error

GetOneByIDRBACInterface returns one object by ID

func (*Mongo) GetOneRBAC

func (db *Mongo) GetOneRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, perm backd.Permission, database, collection string, query map[string]interface{}) (map[string]interface{}, error)

GetOneRBAC returns one object by query

func (*Mongo) Insert

func (db *Mongo) Insert(ctx context.Context, database, collection string, this interface{}) (*mongo.InsertOneResult, error)

Insert a new entry on the collection, returns errors if any

func (*Mongo) InsertRBAC

func (db *Mongo) InsertRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, database, collection string, this map[string]interface{}) (map[string]interface{}, error)

InsertRBAC a new entry on the collection, adding metadata, returns errors if any

func (*Mongo) InsertRBACInterface

func (db *Mongo) InsertRBACInterface(ctx context.Context, session *pbsessions.Session, isDomain bool, database, collection string, this interface{}) error

InsertRBACInterface a new entry on the collection, metadata and ID must be written in advance

func (*Mongo) IsInitialized

func (db *Mongo) IsInitialized(ctx context.Context, database string) error

IsInitialized returns an error if there is no connection with the DB

func (*Mongo) Update

func (db *Mongo) Update(ctx context.Context, database, collection string, selector, to interface{}) error

Update updates the database by using a selector and an object

func (*Mongo) UpdateByID

func (db *Mongo) UpdateByID(ctx context.Context, database, collection, id string, to interface{}) (err error)

UpdateByID updates the database when object used ObjectID as unique ID

func (*Mongo) UpdateByIDRBAC

func (db *Mongo) UpdateByIDRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, database, collection, id string, this map[string]interface{}) (map[string]interface{}, error)

UpdateByIDRBAC updates the data and metadata on the collections, returning errors if any

func (*Mongo) UpdateByIDRBACInterface

func (db *Mongo) UpdateByIDRBACInterface(ctx context.Context, session *pbsessions.Session, isDomain bool, database, collection, id string, this interface{}) error

UpdateByIDRBACInterface updates the data passed as interface and updates the database if ok

func (*Mongo) VisibleID

func (db *Mongo) VisibleID(ctx context.Context, session *pbsessions.Session, isDomain bool, database, collection string, perm backd.Permission) (all bool, ids []string, err error)

VisibleID returns only those IDs that the user is able to see from a collection

Jump to

Keyboard shortcuts

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