Method: ScraperWiki::API#datastore_sqlite

Defined in:
lib/scraperwiki-api.rb

#datastore_sqlite(shortname, query, opts = {}) ⇒ Array, ...

Note:

The query string parameter is name, not shortname as in the ScraperWiki docs

Queries and extracts data via a general purpose SQL interface.

To make an RSS feed you need to use SQL’s AS keyword (e.g. “SELECT name AS description”) to make columns called title, link, description, guid (optional, uses link if not available) and pubDate or date.

jsondict example output:

[
  {
    "fieldA": "valueA",
    "fieldB": "valueB",
    "fieldC": "valueC",
  },
  ...
]

jsonlist example output:

{
  "keys": ["fieldA", "fieldB", "fieldC"],
  "data": [
    ["valueA", "valueB", "valueC"],
    ...
  ]
}

csv example output:

fieldA,fieldB,fieldC
valueA,valueB,valueC
...

Parameters:

  • shortname (String)

    the scraper’s shortname (as it appears in the URL)

  • query (String)

    a SQL query

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :format (String)

    one of “jsondict”, “jsonlist”, “csv”, “htmltable” or “rss2”

  • :attach (Array, String)

    “;”-delimited list of shortnames of other scrapers whose data you need to access

Returns:

  • (Array, Hash, String)

See Also:



86
87
88
89
90
91
# File 'lib/scraperwiki-api.rb', line 86

def datastore_sqlite(shortname, query, opts = {})
  if Array === opts[:attach]
    opts[:attach] = opts[:attach].join ';'
  end
  request_with_apikey '/datastore/sqlite', {name: shortname, query: query}.merge(opts)
end