Persistence with Orchestrate
07 Oct 2015Orchestrate.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
Create an application at the Orchestrate dashboard. For now, make sure to choose "Amazon US East" datacenter.
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
Use the dashboard to create a collection named 'test'
In the dashboard, for your 'test' collection, try the following:
- list the collection (currently empty). On the "list" tab, just push the green "Send Request" button and see the result in the log.
- create a new "record" (i.e. JSON-encoded object) with a key of "1", and check the logged response.
- list the collection again.
- create a new record, but let Orchestrate auto-generate the key.
- list the collection again.
- modify the record with key "1"
- get just that record using its key.
- delete one of the stored records using its key.
- list the collection again.
Interact with data via Javascript
Now you're ready to manipulate collections from NodeJS!
- In your repo, install the
orchestrate
Node module (npm install --save orchestrate
). - Make a JS file that
require
sorchestrate
and uses its API to create and delete some records. Try to repeat the same steps above, and see the results throughconsole.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
- 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.