7 rows where issue = 672421411 sorted by updated_at descending

View and edit SQL

Suggested facets: created_at (date), updated_at (date)

author_association

issue

  • Support reverse pagination (previous page, has-previous-items) · 7
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
812941818 https://github.com/simonw/datasette/issues/916#issuecomment-812941818 https://api.github.com/repos/simonw/datasette/issues/916 MDEyOklzc3VlQ29tbWVudDgxMjk0MTgxOA== simonw 9599 2021-04-03T23:43:11Z 2021-04-03T23:43:11Z OWNER

Relevant code is some of the most complex in all of Datasette.

https://github.com/simonw/datasette/blob/0a7621f96f8ad14da17e7172e8a7bce24ef78966/datasette/views/table.py#L530-L594

And

https://github.com/simonw/datasette/blob/0a7621f96f8ad14da17e7172e8a7bce24ef78966/datasette/views/table.py#L743-L771

I'll need to think hard about how to refactor this out into something more understandable before implementing previous links.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support reverse pagination (previous page, has-previous-items) 672421411  
812941340 https://github.com/simonw/datasette/issues/916#issuecomment-812941340 https://api.github.com/repos/simonw/datasette/issues/916 MDEyOklzc3VlQ29tbWVudDgxMjk0MTM0MA== simonw 9599 2021-04-03T23:38:37Z 2021-04-03T23:38:37Z OWNER
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support reverse pagination (previous page, has-previous-items) 672421411  
812941112 https://github.com/simonw/datasette/issues/916#issuecomment-812941112 https://api.github.com/repos/simonw/datasette/issues/916 MDEyOklzc3VlQ29tbWVudDgxMjk0MTExMg== simonw 9599 2021-04-03T23:35:55Z 2021-04-03T23:35:55Z OWNER

I tried flipping the direction of the sort and the comparison operators and got this: https://latest.datasette.io/fixtures?sql=select+pk1%2C+pk2%2C+pk3%2C+content+from+compound_three_primary_keys+where+%28%28pk1+%3C+%3Ap0%29%0D%0A++or%0D%0A%28pk1+%3D+%3Ap0+and+pk2+%3C+%3Ap1%29%0D%0A++or%0D%0A%28pk1+%3D+%3Ap0+and+pk2+%3D+%3Ap1+and+pk3+%3C+%3Ap2%29%29+order+by+pk1+desc%2C+pk2+desc%2C+pk3+desc+limit+1+offset+99&p0=a&p1=h&p2=r

select pk1, pk2, pk3, content from compound_three_primary_keys where ((pk1 < :p0)
  or
(pk1 = :p0 and pk2 < :p1)
  or
(pk1 = :p0 and pk2 = :p1 and pk3 < :p2)) order by pk1 desc, pk2 desc, pk3 desc limit 1 offset 99

Which returned a-d-v as desired. I messed around with it to find the limit 1 offset 99 values.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support reverse pagination (previous page, has-previous-items) 672421411  
812940907 https://github.com/simonw/datasette/issues/916#issuecomment-812940907 https://api.github.com/repos/simonw/datasette/issues/916 MDEyOklzc3VlQ29tbWVudDgxMjk0MDkwNw== simonw 9599 2021-04-03T23:33:41Z 2021-04-03T23:33:41Z OWNER

Let's figure out the SQL for this. The most complex case is probably this one: https://latest.datasette.io/fixtures/compound_three_primary_keys?_next=a%2Ch%2Cr

Here's the SQL for that page: https://latest.datasette.io/fixtures?sql=select+pk1%2C+pk2%2C+pk3%2C+content+from+compound_three_primary_keys+where+%28%28pk1+%3E+%3Ap0%29%0A++or%0A%28pk1+%3D+%3Ap0+and+pk2+%3E+%3Ap1%29%0A++or%0A%28pk1+%3D+%3Ap0+and+pk2+%3D+%3Ap1+and+pk3+%3E+%3Ap2%29%29+order+by+pk1%2C+pk2%2C+pk3+limit+101&p0=a&p1=h&p2=r

select pk1, pk2, pk3, content from compound_three_primary_keys where ((pk1 > :p0)
  or
(pk1 = :p0 and pk2 > :p1)
  or
(pk1 = :p0 and pk2 = :p1 and pk3 > :p2)) order by pk1, pk2, pk3 limit 101

Where p0 is a, p1 is h and p2 is r.

Given the above, how would I figure out the correct previous link? It should be https://latest.datasette.io/fixtures/compound_three_primary_keys?_next=a%2Cd%2Cv - a, d, v.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support reverse pagination (previous page, has-previous-items) 672421411  
812940457 https://github.com/simonw/datasette/issues/916#issuecomment-812940457 https://api.github.com/repos/simonw/datasette/issues/916 MDEyOklzc3VlQ29tbWVudDgxMjk0MDQ1Nw== simonw 9599 2021-04-03T23:28:40Z 2021-04-03T23:28:40Z OWNER

I think my ideal implementation for this would be to reverse the order, grab the previous page-size-plus-one items, then return a ?_next=x token that would provide the previous page sorted back in the expected default order.

The alternative would be to have a ?_previous=x token which can be used to paginate backwards in reverse order, but I think this would be confusing as it would result in "hit next page, then hit previous page" returning you to a new state which features rows in the reverse order.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support reverse pagination (previous page, has-previous-items) 672421411  
812804998 https://github.com/simonw/datasette/issues/916#issuecomment-812804998 https://api.github.com/repos/simonw/datasette/issues/916 MDEyOklzc3VlQ29tbWVudDgxMjgwNDk5OA== simonw 9599 2021-04-03T03:47:45Z 2021-04-03T03:47:45Z OWNER
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support reverse pagination (previous page, has-previous-items) 672421411  
812742462 https://github.com/simonw/datasette/issues/916#issuecomment-812742462 https://api.github.com/repos/simonw/datasette/issues/916 MDEyOklzc3VlQ29tbWVudDgxMjc0MjQ2Mg== jungle-boogie 1111743 2021-04-02T22:37:27Z 2021-04-02T22:37:27Z NONE

Yes, this would be nice!

I using Datasette v0.56 and don't see a previous page button.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support reverse pagination (previous page, has-previous-items) 672421411  

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issue_comments] (
   [html_url] TEXT,
   [issue_url] TEXT,
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [created_at] TEXT,
   [updated_at] TEXT,
   [author_association] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [issue] INTEGER REFERENCES [issues]([id])
, [performed_via_github_app] TEXT);
CREATE INDEX [idx_issue_comments_issue]
                ON [issue_comments] ([issue]);
CREATE INDEX [idx_issue_comments_user]
                ON [issue_comments] ([user]);