datahub/docs/tutorial-backends.markdown
2012-07-06 08:49:26 -07:00

3.9 KiB

layout, title, recline-deps, root
layout title recline-deps root
container Tutorial - Backends - Loading data from different sources using Backends true ../

Loading data from different sources using Backends
These set of examples will show you how you can load data from different sources such as Google Docs or the DataHub using Recline

Note: often you are loading data from a given source in order to load it into a Recline Dataset and display it in a View. However, you can also happily use a Backend to load data on its own without using any other part of the Recline library as all the Backends are designed to have no dependency on other parts of Recline.

Overview

Backends connect Dataset and Documents to data from a specific 'Backend' data source. They provide methods for loading and saving Datasets and individuals Documents as well as for bulk loading via a query API and doing bulk transforms on the backend.

You can use a backend directly e.g.

{% highlight javascript %} var backend = recline.Backend.ElasticSearch.fetch({url: ...}); {% endhighlight %}

But more usually the backend will be created or loaded for you by Recline and all you need is provide the identifier for that Backend e.g.

{% highlight javascript %} var dataset = recline.Model.Dataset({ backend: 'backend-identifier' }); {% endhighlight %}

Backend identifiers How do you know the backend identifier for a given Backend? It's just the name of the 'class' in recline.Backend module (but case-insensitive). E.g. recline.Backend.ElasticSearch can be identified as 'ElasticSearch' or 'elasticsearch'.

Included Backends

Backend not on this list that you would like to see? It's very easy to write a new backend -- see below for more details.

Preparing your app

This is as per the quickstart but the set of files is much more limited if you are just using a Backend. Specifically:

{% highlight html %}

{% endhighlight %}

Loading Data from Google Docs

We will be using the following Google Doc. For Recline to be able to access a Google Spreadsheet it must have been 'Published to the Web' (enabled via File -> Publish to the Web menu).

Want a real world example? This Open Data Census micro-app loads data from Google Docs and then displays it on a specialist interface combining a bespoke chooser and a Kartograph (svg-only) map.

{% highlight javascript %} {% include example-backends-gdocs.js %} {% endhighlight %}

Result

 

Writing your own backend

Writing your own backend is easy to do. Details of the required API are in the Backend documentation.