eurostatDb.js
Retrieve and store data from eurostat's API.
Eurostat provides a wealth of information -- it's just pretty hard to get to and use. It provides the data over its API in a very 'rich' xml format that is a bit too overwhelming for many uses. This library aims at making things easier for use in javascript web applications.
I promise
The code has been rewritten to use promises instead of callbacks, so that there are now 2 versions:
- v0: (deprecated) uses callbacks
- v1: uses promises
There is no compatibility between the versions. The use of v1+ is encouraged.
Sample use
v1 (current):
db = eurostatDb();
db.tblQinit("demo_pjan", {FREQ: "A", AGE: "TOTAL"}, {startYear: 1995, endYear: 2015}); //1
db.rstQ("demo_pjan", {SEX: "T", GEO: "NL"}, "TIME ASEC") //2
.then(function (rst) {
$("div#info").prepend("<h2>Total population in the Netherlands:</h2>");
rst.forEach(function (r) {$("ul").append("<li>In " + r.TIME + ": " + r.OBS_VALUE + "</li>");});//3
})
.catch(function (e) {alert(e);});Resulting web page, and other examples, are found in the wiki pages. Check it out!
Reference
Found in the wiki's library reference.
Dependencies
eurostatDb.js depends on
- jQuery (http://jquery.com/)
- q (https://github.com/kriskowal/q) to provide promises
- xml2json (https://github.com/abdmob/x2js) to convert xml into json
- taffydb (https://github.com/typicaljoe/taffydb) to store information
so be sure to include those.
Also, the file all_latest_ESTAT_references=none_detail=full.xml which contains the dataflow names and descriptions, must be located in the js/ directory.
Bower
Package is named eurostat-db.
Include the file eurostatDb.js in your project, and be sure to move/copy the file all_latest_ESTAT_references=none_detail=full.xml into your project's js/ directory as mentioned above.
Suggestions
I'm always interested in feedback and suggestions. Please let me know what you think is good, or what could be better. Thanks!