databases package¶
database module¶
-
class
mindreader.drivers.databases.database.Database(url)¶ Bases:
objectThis class is used to communicate with databases. It is called databases but in fact its a thick layer above it (sometimes called persistence).
Note that all the functions that query the database can return empty objects. It’s the users responsibility to handle that if necessary.
To add a new database, add a file named <name>db.py to this package, with a class named <name>DB, which has an attribute named ‘prefix’ (string), which is the database name. It should implement the functions below. Make sure you update the prefix you chose in ‘supported_dbs’ above.
-
get_snapshot_by_id(user_id, snapshot_id) → dict¶ Returns a snapshot with snapshot_id (metadata, and available topics).
-
get_snapshots_by_user_id(user_id) → list¶ Returns list of snapshots (metadata) that belongs to user with user_id.
-
get_user_by_id(user_id) → dict¶ Returns a user that matches the user_id.
-
get_users() → list¶ Returns the list of available users.
-
insert_data(data: dict)¶ Inserts data to the database. The data should be a dictionary, and contain a ‘metadata’ entry (that is similar to objects/SnapshotMetadata class).
-
insert_user(user: mindreader.objects.user.User)¶ Inserts a user to the database. If user with the same id already exists, it will update his entry.
-
-
mindreader.drivers.databases.database.load_databases()¶ Loads dynamically all the available databases.
-
mindreader.drivers.databases.database.supported_dbs= {'mongodb': <class 'databases.mongodb.MongoDB'>}¶ Mapping of the supported databases, loaded dynamically. Currently available: MongoDB - ‘mongodb’
mongodb module¶
-
class
mindreader.drivers.databases.mongodb.MongoDB(host: str, port: int)¶ Bases:
object-
get_snapshot_by_id(user_id, snapshot_id) → dict¶
-
get_snapshots_by_user_id(user_id) → list¶
-
get_user_by_id(user_id) → dict¶
-
get_users() → list¶
-
insert_data(data)¶
-
insert_user(user: mindreader.objects.user.User)¶
-
prefix= 'mongodb'¶
-