home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 870946764

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association pull_request body repo type active_lock_reason performed_via_github_app reactions draft state_reason
870946764 MDU6SXNzdWU4NzA5NDY3NjQ= 1312 how to query many-to-many relationship via json API? 5268174 open 0     0 2021-04-29T12:09:49Z 2021-04-29T12:09:49Z   NONE  

Hi,

Firstly thanks for Datasette, it's great!

I'm trying to use the JSON API to query data from a Datasette instance. I have a simple 3 table many-to-many relationship, like so:

category - list of categories document - list of documents document_category - join table (a category contains many documents, and a document can be a member of multiple categories)

the document_category table foreign keys to the other two using their respective row_ids.

Now I want to return "all documents within category X" but I cannot see a way to do this without executing two queries; the first to lookup the row_id of category X, and the second to join document with document_category where category ID is <id>.

I could easily write this in SQL, but this makes programmatic handling of pagination much more difficult (we'd have to dynamically modify the SQL to select the row_id and include the correct where and limit clauses).

Is there a way to achieve this using the JSON API?

107914493 issue    
{
    "url": "https://api.github.com/repos/simonw/datasette/issues/1312/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
   

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 0 rows from issue in issue_comments
Powered by Datasette · Queries took 0.992ms · About: github-to-sqlite