Meya provides a fully managed, highly scaleable cloud-based database that you can use to store data for your bot.

🚧

Python-only

The Meya database is only available for Python components.

Basic concepts

  • functions as a key/value database without a schema
  • data is conveniently scoped to make common operations simple
    • bot, user, flow and the more generic table
  • the full datastore API can be accessed from within your component code
  • collections of data can be queried and sorted with .filter()

The kitchen sink

The following code demonstrates many of the possible database operations available to you. All access to the datastore is provided by the db object initialized with your component.

from meya import Component


class TestDB(Component):
    def start(self):
        # (A) CONTEXT OBJECTS
        print self.db.bot.id
        print self.db.user.id
        print self.db.flow.id
        
        # set information
        print self.db.bot.set('alive', True)
        print self.db.user.set('name', "Nikola Tesla")
        print self.db.flow.set('preference', "electric")
        
        # access specific information
        print self.db.flow.get('preference')
        print self.db.user.get('name')
        print self.db.bot.get('alive')
        
        # retrieve all you know about your context
        print self.db.bot.all()
        print self.db.user.all()
        print self.db.flow.all()

        # (B) LISTS
        # all users
        print self.db.users.all()
        print self.db.users.filter(name="Nikola Tesla")
        print self.db.users.get(self.db.user.id)

        # all flows
        print self.db.flows.all()
        print self.db.flows.filter(foo="bar")
        print self.db.flows.get(self.db.flow.id)

        # (C) TABLES
        # we'll write some data to an `order` table
        print self.db.table('order').add({'item': "A", 'price': 102})
        print self.db.table('order').add({'item': "B", 'price': 50})
        print self.db.table('order').add({'item': "C", 'price': 19})
        print self.db.table('order').all()

        # lists orders [C, B] in that order, since A > $100
        print self.db.table('order').filter(
          price__lt=100, order_by=['-item'])

        # get the 1st order matching item=A and retrieve it's ID
        order = self.db.table('order').filter(item='A')[0]

        # update the order with a price
        self.db.table('order').update(order['id'], {'price': 108.12})

        # kind of reduntant, really. Just gets itself
        print self.db.table('order').get(order['id'])

        return self.respond(message=None, action="next")