Scope
The database is broken down into four scopes. Each scope is responsible for storing different type of data.
The usage will look like:
self.db.<scope>.<method>(param1, param2, ...)So for example, calling a get method on the user scope:
# returns "Nikola Tesla"
self.db.user.get('name')Scope | Description | Use-case | Collection? |
|---|---|---|---|
| Global data about your bot. | Store the online status of your business. | No |
| Information about the current user. | Store the user's date of birth. |
|
| Information stored within the current flow. | Store the sub-total for the current transaction. |
|
| Generic datastore for storing custom table data. | Create and store transaction data in an "orders" table. |
|
Collections
The user, flow and table scopes have list behaviour. This means that you can query multiple rows of data via the users, flows and table objects respectively.
Remember to accessuserandflowcollections asusersandflows.
# retrieve a specific user
user = self.db.users.get("Uxxxxxxx")
# retrieve users with the name "Nikola"
users = self.db.users.filter(name="Nikola")
# retrieve flows which the order key contains "pizza"
users = self.db.flows.filter(order__contains="pizza")
# add an order for a burrito
order = {
'item': 'Fish burrito',
'price': 8.99,
'created_at': time.time(),
'user_id': self.db.user.id
}
self.db.table('orders').add(order)
# retrieve the user's most recent orders
orders = self.db.table('orders').filter(user_id=self.db.user.id)Updated 5 months ago
