Does the Jibo SDK have any database built-in for its Skills?

Does the Jibo SDK have any database built-in for its Skills?

At the present time the SDK does not include its own built in database.

There are some resources that I have seen other folks use at the moment for persistent storage.

I have seen some people use NeDB as a resource when looking into storage. I have also seen developers use some of the open database solutions out there like Mongo or some of the others on this list.

In the case of NeDB, the first time I used it was for Jibo, but I’ve found it very simple to jump into.

To get anyone started, first make sure you install NeDB in your skill with:

npm install nedb

Then connect to it globally with:

notepad.NeDB = require('nedb');

I use the above to make the DB connection available throughout my skill. Then, when connecting to a table in a particular script, just use:

var NeDB = notepad.NeDB;
var myDB = new NeDB({filename:'db/name_of_table.json',autoload:true});

For your queries (find, insert, delete), just reference the NeDB docs:

1 Like

I’m finding NeDB useful, too. Just a note, since you’ve set autoload to true, I don’t think you need to do a myDB.loadDatabase();

I put all my database code in a class inside a module. Then, early in my Behavior tree in an ExecuteScript I require the module and set a notepad variable to be a new instance of the class. Then I get to the datastore via functions in the class, so all my db code stays in one .js file.

Oh, yeah, you should probably add “nedb”: “^1.8.0” to the dependencies in your package.json also.

The trickiest thing for me was figuring out how to do the callbacks to actually use the data once it was fetched. I hadn’t really wrapped my head around the whole asynchronicity thing, and NeDB was the thing that helped me do it.

1 Like

Thanks, Chris. You’re right about the loadDatabase() call not being needed…I had added the “autoload:true” parameter later on in my development, and just forgot to remove the now unnecessary loadDatabase(). Thanks also for mentioning adding “nedb”: “^1.8.0” to the dependencies.

Per NeDB being asynchronous, for developers who aren’t used to that, you can just wrap your database queries in an ExecuteScriptAsync instead and call “success()” after the data has been retrieved if you need the robot to wait for the data before proceeding. For instance…

var myDB = new NeDB({filename:'db/name_of_table.json',autoload:true});
myDB.find({}, function(err,allItemsARRAY){
    notepad.itemList = allItemsARRAY;

…this code basically fetches an entire table, stores it in an array, and saves it to the notepad. When used within a ExecuteScriptAsync behavior, Jibo will literally pause until the data has been fetched, then continue once it has.


@michael has excellently produced some further tips and tricks for using NeDB in this post and I provided the following info on a future Jibo official way of doing this: