JS Evening

Persistence with Orchestrate

Orchestrate.io

Today we'll learn about Orchestrate.io, a database-as-a-service.

The Orchestrate API

Orchestrate.io stores all your data in its own database. You retrieve data by making HTTP requests to their web API. They offer a Node package to interact with their API without having to craft raw HTTP requests. It's fairly straightforward:

db.put('users', 'unique-user-id', {
  "name": "Shackleton Cat",
  "hometown": "Portland, OR",
  "twitter": "@soundofcrunchysnacks"
})
.then(function (res) {
  console.log(res.statusCode);
})
.fail(function (err) {});
db.get('users', 'unique-user-id')
.then(function (res) {
  console.log(res.body);
})
.fail(function (err) {});

Exercise: Orchestrate.io

  1. Sign up for an account on orchestrate.io.

  2. Create an application at the Orchestrate dashboard. For now, make sure to choose "Amazon US East" datacenter.

  3. In your project repo, make a new file called "config.js". This will hold your database access key, and should remain private! In the file, paste your new Orchestrate app's API key like so:

module.exports = {
       dbkey : "12345678-90ab-cdef-1234-ab0123456789" // My Orch API key
}

Also edit the .gitignore file in that repo and add the line "config.js", so that your config.js file is not accidentally added to your repo.

Interact with data via Dashboard

  1. Use the dashboard to create a collection named 'test'

  2. In the dashboard, for your 'test' collection, try the following:

    1. list the collection (currently empty). On the "list" tab, just push the green "Send Request" button and see the result in the log.
    2. create a new "record" (i.e. JSON-encoded object) with a key of "1", and check the logged response.
    3. list the collection again.
    4. create a new record, but let Orchestrate auto-generate the key.
    5. list the collection again.
    6. modify the record with key "1"
    7. get just that record using its key.
    8. delete one of the stored records using its key.
    9. list the collection again.

Interact with data via Javascript

Now you're ready to manipulate collections from NodeJS!

  1. In your repo, install the orchestrate Node module (npm install --save orchestrate).
  2. Make a JS file that requires orchestrate and uses its API to create and delete some records. Try to repeat the same steps above, and see the results through console.log()s. Check out the api docs for more on how to work with the API through the Node client.

Begin using Orchestrate in your project

  1. Make a file 'reset-db.js' which will reset a particular collection in your database to contain only a few test records of your choice.