Documentation ¶
Index ¶
- Variables
- func NewXID() xid.ID
- type Mongo
- func (db *Mongo) Can(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) bool
- func (db *Mongo) Client() *mongo.Client
- func (db *Mongo) Count(ctx context.Context, database, collection string, query map[string]interface{}) (int64, error)
- func (db *Mongo) CreateApplicationDatabase(ctx context.Context, name string) (err error)
- func (db *Mongo) CreateBackdDatabases(ctx context.Context) (err error)
- func (db *Mongo) CreateCollection(ctx context.Context, database, collection string, ...) (err error)
- func (db *Mongo) CreateDomainDatabase(ctx context.Context, name string) (err error)
- func (db *Mongo) CreateIndex(ctx context.Context, database, collection string, keys map[string]interface{}, ...) (err error)
- func (db *Mongo) Delete(ctx context.Context, database, collection string, ...) (count int64, err error)
- func (db *Mongo) DeleteByID(ctx context.Context, database, collection, id string) (count int64, err error)
- func (db *Mongo) DeleteByIDRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) (int64, error)
- func (db *Mongo) DeleteByQueryRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) (int64, error)
- func (db *Mongo) GetMany(ctx context.Context, database, collection string, query interface{}, ...) (err error)
- func (db *Mongo) GetManyRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) error
- func (db *Mongo) GetOne(ctx context.Context, database, collection string, query, this interface{}) error
- func (db *Mongo) GetOneByID(ctx context.Context, database, collection, id string, this interface{}) error
- func (db *Mongo) GetOneByIDRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) (map[string]interface{}, error)
- func (db *Mongo) GetOneByIDRBACInterface(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) error
- func (db *Mongo) GetOneRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) (map[string]interface{}, error)
- func (db *Mongo) Insert(ctx context.Context, database, collection string, this interface{}) (*mongo.InsertOneResult, error)
- func (db *Mongo) InsertRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) (map[string]interface{}, error)
- func (db *Mongo) InsertRBACInterface(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) error
- func (db *Mongo) IsInitialized(ctx context.Context, database string) error
- func (db *Mongo) Update(ctx context.Context, database, collection string, selector, to interface{}) error
- func (db *Mongo) UpdateByID(ctx context.Context, database, collection, id string, to interface{}) (err error)
- func (db *Mongo) UpdateByIDRBAC(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) (map[string]interface{}, error)
- func (db *Mongo) UpdateByIDRBACInterface(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) error
- func (db *Mongo) VisibleID(ctx context.Context, session *pbsessions.Session, isDomain bool, ...) (all bool, ids []string, err error)
Constants ¶
This section is empty.
Variables ¶
var (
ErrDatabaseNotInitialized = errors.New("Database not initialized")
)
Errors
Functions ¶
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 (*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) 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 ¶
CreateApplicationDatabase creates the required collection for an application to be usable
func (*Mongo) CreateBackdDatabases ¶
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 ¶
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 ¶
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