api.db_connectors package¶
api.db_connectors.MongoConnector module¶
-
class
api.db_connectors.MongoConnector.MongoConnector(db_url)¶ Bases:
objectA connector class that interacts with MongoDB servers and provides an abstraction for queries Supported scheme: mongodb://
-
get_all_users()¶ Queries the database for a list of all the users
- Returns
(list) A list of user documents
-
get_result(user_id, snapshot_id, result_name)¶ Gets a specific result’s details from a specified snapshot by a specified user
- Parameters
user_id – The id of the desired user
snapshot_id – The id of the desired snapshot
result_name – The name of the desired result
- Returns
(dict) A result dict with all its fields or None if the snapshot or result are not found
-
get_snapshot(user_id, snapshot_id)¶ Queries the database for a specific snapshot of a specific user
- Parameters
user_id – The id of the desired user
snapshot_id – The id of the desired snapshot
- Returns
(dict) A snapshot document or None if snapshot is not found
-
get_user(id)¶ Queries the database for a specific user
- Parameters
id – The id of the desired user
- Returns
(dict) A user document or None if user is not found
-
get_user_snapshots(user_id)¶ Queries the database for all the snapshots of a specific user
- Parameters
user_id – The id of the desired user
- Returns
(list) A list of snapshot documents
-
Module contents¶
This package contains all the connector classes to enable the API to connect to different databases To add a connector to a new database, simply add a class to this folder and decorate it with @connector and your desired url scheme
-
api.db_connectors.connector(scheme)¶ A decorator function to decorate classes that connect to a certain type of database. In case you want to use any database other than MongoDB, add a connector class similar to the given one, place it in the db_connectors subfolder and decorate it with this
- Parameters
scheme – The URL scheme that corresponds to the database that is being used by the connector