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')
ScopeDescriptionUse-caseCollection?
botGlobal data about your bot.Store the online status of your business.No
userInformation about the current user.Store the user's date of birth.Yes, via users
flowInformation stored within the current flow.Store the sub-total for the current transaction.Yes, via flows
tableGeneric datastore for storing custom table data.Create and store transaction data in an "orders" table.Yes, table only behaves as a collection.

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 access user and flow collections as users and flows.

# 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)