Databases

Learn how to store user specific data to databases with the Jovo Persistence Layer.

Jovo Persistence Layer

This is an abstraction layer for persisting data across sessions. By default, the file-based system will be used so you can start right away when prototyping locally.

Configuration

You can add different database integrations in the Jovo app constructor. This is the default configuration:

Save Data

This will save data with your user's userID as a mainKey, and a key and a value specified by you.

The easiest way to do so is to use the user object for this:

Load Data

After you saved data, you can use a key to retrieve a value from the database.

Again, you can use the user object for this:

Delete Data

This will delete a data point from the database, specified by a key.

Delete a User

This will delete your whole user's data (the mainKey) from the database.

FilePersistence

Note: This is the default database integration.

The FilePersistence integration allows you to easily store user session data in a JSON file. This is especially helpful for local development and prototyping. Data will be stored to a db.json file by default.

This sort of data persistence is enabled by default. The db.json can be found in the the following folder:

And this is an example how the file structure looks like, with the userID as a mainKey and some persisted data with someKey and someValue, which can be added with this.user().data.someKey = 'someValue';:

DynamoDB

Tutorial: Add DynamoDB to Store User Data

The DynamoDB integration allows you to store user session data in the NoSQL service running on AWS. This integration is especially convenient if you're running your voice app on AWS Lambda. Learn more about DynamoDB here: aws.amazon.com/dynamodb.

DynamoDB for Apps Hosted on AWS Lambda

If you're running on Lambda, you can simply integrate a DynamoDB table like this:

This will create a table with a name specified by you, and use this to store and load data. To make it work, you need to give your Lambda Role DynamoDB permissions.

You can find out more in the official documentation by Amazon: AWS Lambda Permissions Model.

DynamoDB for Apps Not Hosted on AWS Lambda

In case you're hosting your voice app somewhere else, you can add DynamoDB with the following:

You can find a detailed guide by Amazon about setting up your DynamoDB for programmatic access here: Setting Up DynamoDB (Web Service).

DynamoDB Troubleshooting

Here are a few things you need to consider when switching from a different database to DynamoDB

  • DynamoDB does not allow empty strings ("") as values: If you use them, please switch to null or a different value

Comments and Questions

Any specific questions? Just drop them below. Alternatively, you can also fill out this feedback form. Thank you!

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.