home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

1 row where issue = 1058072543, "updated_at" is on date 2021-12-19 and user = 9599 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

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

user 1

  • simonw · 1 ✖

issue 1

  • Complete refactor of TableView and table.html template · 1 ✖

author_association 1

  • OWNER 1
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
997472214 https://github.com/simonw/datasette/issues/1518#issuecomment-997472214 https://api.github.com/repos/simonw/datasette/issues/1518 IC_kwDOBm6k_c47dDfW simonw 9599 2021-12-19T22:22:08Z 2021-12-19T22:22:08Z OWNER

I sketched out a chained SQL builder pattern that might be useful for further tidying up this code - though with the new plugin hook I'm less excited about it than I was:

```python class TableQuery: def init(self, table, columns, pks, is_view=False, prev=None): self.table = table self.columns = columns self.pks = pks self.is_view = is_view self.prev = prev

    # These can be changed for different instances in the chain:
    self._where_clauses = None
    self._order_by = None
    self._page_size = None
    self._offset = None
    self._select_columns = None

    self.select_all_columns = '*'
    self.select_specified_columns = '*'

@property
def where_clauses(self):
    wheres = []
    current = self
    while current:
        if current._where_clauses is not None:
            wheres.extend(current._where_clauses)
        current = current.prev
    return list(reversed(wheres))

def where(self, where):
    new_cls = TableQuery(self.table, self.columns, self.pks, self.is_view, self)
    new_cls._where_clauses = [where]
    return new_cls

@classmethod
async def introspect(cls, db, table):
    return cls(
        table,
        columns = await db.table_columns(table),
        pks = await db.primary_keys(table),
        is_view = bool(await db.get_view_definition(table))
    )

@property
def sql_from(self):
    return f"from {self.table}{self.sql_where}"

@property
def sql_where(self):
    if not self.where_clauses:
        return ""
    else:
        return f" where {' and '.join(self.where_clauses)}"

@property
def sql_no_order_no_limit(self):
    return f"select {self.select_all_columns} from {self.table}{self.sql_where}"

@property
def sql(self):
    return f"select {self.select_specified_columns} from {self.table} {self.sql_where}{self._order_by} limit {self._page_size}{self._offset}"

@property
def sql_count(self):
    return f"select count(*) {self.sql_from}"


def __repr__(self):
    return f"<TableQuery sql={self.sql}>"

Usage:python from datasette.app import Datasette ds = Datasette(memory=True, files=["/Users/simon/Dropbox/Development/datasette/fixtures.db"]) db = ds.get_database("fixtures") query = await TableQuery.introspect(db, "facetable") print(query.where("foo = bar").where("baz = 1").sql_count)

'select count(*) from facetable where foo = bar and baz = 1'

```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Complete refactor of TableView and table.html template 1058072543  

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]);
Powered by Datasette · Queries took 462.228ms · About: github-to-sqlite