Query the Data Delivery Network
Query the DDNThe easiest way to query any data on Splitgraph is via the "Data Delivery Network" (DDN). The DDN is a single endpoint that speaks the PostgreSQL wire protocol. Any Splitgraph user can connect to it at data.splitgraph.com:5432
and query any version of over 40,000 datasets that are hosted or proxied by Splitgraph.
For example, you can query the washington_state_public_library_services_during
table in this repository, by referencing it like:
"wa-gov/washington-state-public-library-services-during-ma99-sxnd:latest"."washington_state_public_library_services_during"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"source", -- URL of the best single source for this information. An empty cell means the information came from direct communication with Washington State Library staff.
"suspenddates_fines", -- "Yes" mean due dates have been extended and overdue fines do not accrue during closure, or the library reminds patrons that the library has no such fines.
"lastwebsitecheckdate", -- The most recent date that the library's website or social media site was checked by Washington State Library staff, or Washington State Library staff communicated with the library.
"eresources", -- "Yes" means the library highlights or promotes existing electronic resources, e.g., ebooks, audiobooks, online databases and collections.
"notes", -- Details about any of the preceding information, including sources of information outside provided URLs.
"printing", -- "Yes" means patrons can send documents online to the library, for printing and pick-up.
"eprograms", -- "Yes" means the library has generated online programs (e.g., storytime), activities or content (e.g., staff video messages to the community) during closure. This may be live or recorded.
"emailassist", -- "Yes" means the library says it's answering telephone, email, chat or online form inquiries from patrons during closure. "No" means the library says it is not responding to these channels during closure.
"facebook", -- URL of the library's Facebook page, if applicable. This might feature links to online resources and events, as well as staff-generated videos and activities for patrons.
"othersocialmedia", -- URL of the library's Twitter, YouTube, Instagram, blog or other social media sites, if used for services during COVID-19 closure.
"entrybyappt", -- "Yes" means patrons may enter library facilities by appointment, or only for specific time-limited or by-appointment services (e.g., in-person computer use, printing), or the library restricts entry during certain hours to patrons with higher COVID-19-related risks. See "Notes."
"facilityreopened", -- The date (or, "Yes (n.d.)" when date isn't known) that the library has most recently reopened some or all of its facilities, subject to time and capacity limits. Services are likely restricted, but includes more than pick-up or printing (e.g., browsing, computer use). Per public health requirements, masks and social distancing required. See Notes column for further details.
"facilityaccess", -- Date of first facility closures in response to pandemic, and projected reopening date (or "until further notice").
"library_system", -- Name of the library system
"publicwifi", -- "Yes" means patrons can access wifi from just outside library buildings/facilities (e.g., from the parking lot).
"bookdropopen", -- "Yes" means the library says book return dropboxes are open. "No" means the library has said the drops are closed or has asked patrons to keep borrowed materials until reopening.
"curbside", -- "Yes" means the library offers some services to patrons from their cars, such as picking up holds or prepared "grab bags" of content; or allows "take-out" or "grab and go" services, where patrons enter the library for a few minutes only to pick up holds or other content.
"hotspotlending", -- "Yes" means the library loans mobile devices that provide cellular internet connectivity.
"deviceonprem", -- "Yes" means the library has computers, laptops, tablets or other equipment for using online content available for patron use at the library location. This may include public devices inside the library, or devices lent for temporary use on the library grounds.
"librarycardaccess", -- "Yes" means the library highlights online sign-up or renewal for its cards, or other assistance with card access during closure (e.g., helping existing card holders reactivate a card or assign a PIN). This applies to cards for the library system itself, not cards for e-resource consortia such as Washington Anytime Library.
"devicelendinghome" -- "Yes" means the library lends computers, laptops, tablets or other devices for using online content at home. This category does not include lending of hotspots for connection to the internet.
FROM
"wa-gov/washington-state-public-library-services-during-ma99-sxnd:latest"."washington_state_public_library_services_during"
LIMIT 100;
Connecting to the DDN is easy. All you need is an existing SQL client that can connect to Postgres. As long as you have a SQL client ready, you'll be able to query wa-gov/washington-state-public-library-services-during-ma99-sxnd
with SQL in under 60 seconds.
Query Your Local Engine
bash -c "$(curl -sL https://github.com/splitgraph/splitgraph/releases/latest/download/install.sh)"
Read the installation docs.
Splitgraph Cloud is built around Splitgraph Core (GitHub), which includes a local Splitgraph Engine packaged as a Docker image. Splitgraph Cloud is basically a scaled-up version of that local Engine. When you query the Data Delivery Network or the REST API, we mount the relevant datasets in an Engine on our servers and execute your query on it.
It's possible to run this engine locally. You'll need a Mac, Windows or Linux system to install sgr
, and a Docker installation to run the engine. You don't need to know how to actually use Docker; sgr
can manage the image, container and volume for you.
There are a few ways to ingest data into the local engine.
For external repositories, the Splitgraph Engine can "mount" upstream data sources by using sgr mount
. This feature is built around Postgres Foreign Data Wrappers (FDW). You can write custom "mount handlers" for any upstream data source. For an example, we blogged about making a custom mount handler for HackerNews stories.
For hosted datasets (like this repository), where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr clone
and sgr checkout
.
Cloning Data
Because wa-gov/washington-state-public-library-services-during-ma99-sxnd:latest
is a Splitgraph Image, you can clone the data from Spltgraph Cloud to your local engine, where you can query it like any other Postgres database, using any of your existing tools.
First, install Splitgraph if you haven't already.
Clone the metadata with sgr clone
This will be quick, and does not download the actual data.
sgr clone wa-gov/washington-state-public-library-services-during-ma99-sxnd
Checkout the data
Once you've cloned the data, you need to "checkout" the tag that you want. For example, to checkout the latest
tag:
sgr checkout wa-gov/washington-state-public-library-services-during-ma99-sxnd:latest
This will download all the objects for the latest
tag of wa-gov/washington-state-public-library-services-during-ma99-sxnd
and load them into the Splitgraph Engine. Depending on your connection speed and the size of the data, you will need to wait for the checkout to complete. Once it's complete, you will be able to query the data like you would any other Postgres database.
Alternatively, use "layered checkout" to avoid downloading all the data
The data in wa-gov/washington-state-public-library-services-during-ma99-sxnd:latest
is 0 bytes. If this is too big to download all at once, or perhaps you only need to query a subset of it, you can use a layered checkout.:
sgr checkout --layered wa-gov/washington-state-public-library-services-during-ma99-sxnd:latest
This will not download all the data, but it will create a schema comprised of foreign tables, that you can query as you would any other data. Splitgraph will lazily download the required objects as you query the data. In some cases, this might be faster or more efficient than a regular checkout.
Read the layered querying documentation to learn about when and why you might want to use layered queries.
Query the data with your existing tools
Once you've loaded the data into your local Splitgraph Engine, you can query it with any of your existing tools. As far as they're concerned, wa-gov/washington-state-public-library-services-during-ma99-sxnd
is just another Postgres schema.