PostgREST
In addition to the DDN which lets you run arbitrary SQL queries, every dataset on Splitgraph also has a read-only OpenAPI-compatible endpoint that you can use to query it, powered by PostgREST. While less powerful, PostgREST queries are simpler to construct than SQL.
Example:
$ curl https://data.splitgraph.com/splitgraph-demo/votes_by_state/latest/-/rest/votes_by_state?state_postal=eq.DC
[{"candidate_normalized":"clinton","state_postal":"DC","total_votes":282830},
{"candidate_normalized":"in","state_postal":"DC","total_votes":6551},
{"candidate_normalized":"johnson","state_postal":"DC","total_votes":4906},
{"candidate_normalized":"stein","state_postal":"DC","total_votes":4258},
{"candidate_normalized":"trump","state_postal":"DC","total_votes":12723}]
If you're using the sgr
CLI, you can also use a shorthand, sgr cloud curl
,
that takes care of all the scaffolding around generating the URL and making sure
you're logged in:
$ sgr cloud curl splitgraph-demo/votes_by_state "votes_by_state?state_postal=eq.DC"
[{"candidate_normalized":"clinton","state_postal":"DC","total_votes":282830},
{"candidate_normalized":"in","state_postal":"DC","total_votes":6551},
{"candidate_normalized":"johnson","state_postal":"DC","total_votes":4906},
{"candidate_normalized":"stein","state_postal":"DC","total_votes":4258},
{"candidate_normalized":"trump","state_postal":"DC","total_votes":12723}]
For more information on writing PostgREST queries, see the PostgREST docs.