home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1651904060

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions issue performed_via_github_app
https://github.com/simonw/datasette/pull/2053#issuecomment-1651904060 https://api.github.com/repos/simonw/datasette/issues/2053 1651904060 IC_kwDOBm6k_c5idg48 9599 2023-07-26T14:19:00Z 2023-07-26T15:25:15Z OWNER

Worth noting that the register_output_renderer() is actually pretty easy to extend, because it returns a dictionary which could have more keys (like the required set of extras) added to it: python @hookimpl def register_output_renderer(datasette): return { "extension": "test", "render": render_demo, "can_render": can_render_demo, # Optional } https://docs.datasette.io/en/0.64.3/plugin_hooks.html#register-output-renderer-datasette

One slight hiccup with that plugin hook is this:

rows - list of sqlite3.Row objects

I could turn that into a Datasette defined object that behaves like a sqlite3.Row though, which would give me extra flexibility in the future.

A bit tricky though since it's implemented in C for performance: https://github.com/python/cpython/blob/b0202a4e5d6b629ba5acbc703e950f08ebaf07df/Modules/_sqlite/row.c

Pasted that into Claude for the following explanation:

  • pysqlite_Row is the structure defining the Row object. It contains the tuple of data (self->data) and description of columns (self->description).
  • pysqlite_row_new() is the constructor which creates a new Row object given a cursor and tuple of data.
  • pysqlite_row_dealloc() frees the memory when Row object is deleted.
  • pysqlite_row_keys() returns the column names of the row.
  • pysqlite_row_length() and pysqlite_row_subscript() implement sequence like behavior to access row elements by index.
  • pysqlite_row_subscript() also allows accessing by column name by doing a lookup in description.
  • pysqlite_row_hash() and pysqlite_row_richcompare() implement equality checks and hash function.

I could use protocols in Python to make my own DatasetteRow which can be used interchangeably with sqlite3.Row - https://docs.python.org/3/library/typing.html#typing.Protocol

Turned this into a TIL: https://til.simonwillison.net/python/protocols

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
1656432059  
Powered by Datasette · Queries took 1.2ms · About: github-to-sqlite