home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

26 rows where "updated_at" is on date 2021-01-03 and user = 9599 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

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

issue 11

  • Use _counts to speed up counts 7
  • reset_counts() method and command 4
  • changes to allow for compound foreign keys 3
  • Prettier package not actually being cached 3
  • JavaScript plugin hooks mechanism similar to pluggy 2
  • sqlite-utils insert -f colname - for configuring full-text search 2
  • sqlite-utils should suggest --csv if JSON parsing fails 1
  • "datasette insert" command and plugin hook 1
  • database.triggers_dict introspection property 1
  • Rename .escape() to .quote() 1
  • "sqlite-utils triggers" command 1

user 1

  • simonw · 26 ✖

author_association 1

  • OWNER 26
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
753690280 https://github.com/simonw/datasette/issues/983#issuecomment-753690280 https://api.github.com/repos/simonw/datasette/issues/983 MDEyOklzc3VlQ29tbWVudDc1MzY5MDI4MA== simonw 9599 2021-01-03T23:13:30Z 2021-01-03T23:13:30Z OWNER

Oh that's interesting, I hadn't thought about plugins firing events - just responding to events fired by the rest of the application.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
JavaScript plugin hooks mechanism similar to pluggy 712260429  
753671902 https://github.com/simonw/sqlite-utils/issues/219#issuecomment-753671902 https://api.github.com/repos/simonw/sqlite-utils/issues/219 MDEyOklzc3VlQ29tbWVudDc1MzY3MTkwMg== simonw 9599 2021-01-03T20:31:04Z 2021-01-03T20:32:13Z OWNER

A table.has_count_triggers property.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
reset_counts() method and command 777707544  
753671235 https://github.com/simonw/sqlite-utils/issues/219#issuecomment-753671235 https://api.github.com/repos/simonw/sqlite-utils/issues/219 MDEyOklzc3VlQ29tbWVudDc1MzY3MTIzNQ== simonw 9599 2021-01-03T20:25:10Z 2021-01-03T20:25:10Z OWNER

To detect tables, look at the names of the triggers - {table}{counts_table}_insert and {table}{counts_table}_delete.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
reset_counts() method and command 777707544  
753671009 https://github.com/simonw/sqlite-utils/issues/219#issuecomment-753671009 https://api.github.com/repos/simonw/sqlite-utils/issues/219 MDEyOklzc3VlQ29tbWVudDc1MzY3MTAwOQ== simonw 9599 2021-01-03T20:22:53Z 2021-01-03T20:22:53Z OWNER

I think this should be accompanied by a sqlite-utils reset-counts command.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
reset_counts() method and command 777707544  
753670833 https://github.com/simonw/sqlite-utils/issues/219#issuecomment-753670833 https://api.github.com/repos/simonw/sqlite-utils/issues/219 MDEyOklzc3VlQ29tbWVudDc1MzY3MDgzMw== simonw 9599 2021-01-03T20:20:54Z 2021-01-03T20:20:54Z OWNER

This is a little tricky. We should assume that the existing values in the _counts table cannot be trusted at all when this method is called - so we should probably clear that table entirely and then re-populate it.

But that means we need to figure out which tables in the database have the counts triggers defined.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
reset_counts() method and command 777707544  
753668099 https://github.com/simonw/sqlite-utils/issues/215#issuecomment-753668099 https://api.github.com/repos/simonw/sqlite-utils/issues/215 MDEyOklzc3VlQ29tbWVudDc1MzY2ODA5OQ== simonw 9599 2021-01-03T19:55:53Z 2021-01-03T19:55:53Z OWNER

So if you instantiate the Database() constructor with use_counts_table=True any access to the .count properties will go through this table - otherwise regular count(*) queries will be executed.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Use _counts to speed up counts 777535402  
753665521 https://github.com/simonw/sqlite-utils/issues/215#issuecomment-753665521 https://api.github.com/repos/simonw/sqlite-utils/issues/215 MDEyOklzc3VlQ29tbWVudDc1MzY2NTUyMQ== simonw 9599 2021-01-03T19:31:33Z 2021-01-03T19:31:33Z OWNER

I'm having second thoughts about this being the default behaviour. It's pretty weird. I feel like HUGE databases that need this are rare, so having it on by default doesn't make sense.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Use _counts to speed up counts 777535402  
753662490 https://github.com/simonw/sqlite-utils/issues/215#issuecomment-753662490 https://api.github.com/repos/simonw/sqlite-utils/issues/215 MDEyOklzc3VlQ29tbWVudDc1MzY2MjQ5MA== simonw 9599 2021-01-03T19:05:53Z 2021-01-03T19:05:53Z OWNER

Idea: a .execute_count() method that never uses the cache.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Use _counts to speed up counts 777535402  
753661292 https://github.com/simonw/sqlite-utils/issues/215#issuecomment-753661292 https://api.github.com/repos/simonw/sqlite-utils/issues/215 MDEyOklzc3VlQ29tbWVudDc1MzY2MTI5Mg== simonw 9599 2021-01-03T18:56:06Z 2021-01-03T18:56:23Z OWNER

Another option: on creation of the Database() object, check to see if the _counts table exists and use that as the default for a use_counts_table property. Also flip that property to True if the user calls .enable_counts() at any time.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Use _counts to speed up counts 777535402  
753661158 https://github.com/simonw/sqlite-utils/issues/215#issuecomment-753661158 https://api.github.com/repos/simonw/sqlite-utils/issues/215 MDEyOklzc3VlQ29tbWVudDc1MzY2MTE1OA== simonw 9599 2021-01-03T18:55:16Z 2021-01-03T18:55:16Z OWNER

Alternative implementation: provided db.should_trust_counts is True, try running the query: sql select count from _counts where [table] = ? If the query fails to return a result OR throws an error because the table doesn't exist, run the count(*) query.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Use _counts to speed up counts 777535402  
753660814 https://github.com/simonw/sqlite-utils/issues/215#issuecomment-753660814 https://api.github.com/repos/simonw/sqlite-utils/issues/215 MDEyOklzc3VlQ29tbWVudDc1MzY2MDgxNA== simonw 9599 2021-01-03T18:53:05Z 2021-01-03T18:53:05Z OWNER

Here's the current .count property: https://github.com/simonw/sqlite-utils/blob/036ec6d32313487527c66dea613a3e7118b97459/sqlite_utils/db.py#L597-L609

It's implemented on Queryable which means it's available on both Table and View - the optimization doesn't make sense for views.

I'm a bit cautious about making that property so much more complex. In order to decide if it should try the _counts table first it needs to know:

  • Should it be trusting the counts? I'm thinking a .should_trust_counts property on Database which defaults to True would be good - then advanced users can turn that off if they know the counts should not be trusted.
  • Does the _counts table exist?
  • Are the triggers defined?

Then it can do the query, and if the query fails it can fall back on the count(*). That's quite a lot of extra activity though.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Use _counts to speed up counts 777535402  
753660379 https://github.com/simonw/sqlite-utils/issues/215#issuecomment-753660379 https://api.github.com/repos/simonw/sqlite-utils/issues/215 MDEyOklzc3VlQ29tbWVudDc1MzY2MDM3OQ== simonw 9599 2021-01-03T18:50:15Z 2021-01-03T18:50:15Z OWNER

python def cached_counts(self, tables=None): sql = "select [table], count from {}".format(self._counts_table_name) if tables: sql += " where [table] in ({})".format(", ".join("?" for table in tables)) return {r[0]: r[1] for r in self.execute(sql, tables).fetchall()}

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Use _counts to speed up counts 777535402  
753659260 https://github.com/simonw/sqlite-utils/issues/206#issuecomment-753659260 https://api.github.com/repos/simonw/sqlite-utils/issues/206 MDEyOklzc3VlQ29tbWVudDc1MzY1OTI2MA== simonw 9599 2021-01-03T18:42:01Z 2021-01-03T18:42:01Z OWNER

% sqlite-utils insert blah.db blah global_power_plant_database.csv Error: Invalid JSON - use --csv for CSV or --tsv for TSV files

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils should suggest --csv if JSON parsing fails 761915790  
753657180 https://github.com/simonw/datasette/issues/1169#issuecomment-753657180 https://api.github.com/repos/simonw/datasette/issues/1169 MDEyOklzc3VlQ29tbWVudDc1MzY1NzE4MA== simonw 9599 2021-01-03T18:23:30Z 2021-01-03T18:23:30Z OWNER

Also welcome in that PR would be a bit of documentation for contributors, see #1167 - but no problem if you leave that out, I'm happy to add it later.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Prettier package not actually being cached 777677671  
753653260 https://github.com/simonw/datasette/issues/1169#issuecomment-753653260 https://api.github.com/repos/simonw/datasette/issues/1169 MDEyOklzc3VlQ29tbWVudDc1MzY1MzI2MA== simonw 9599 2021-01-03T17:54:40Z 2021-01-03T17:54:40Z OWNER

And @benpickles yes I would land that pull request straight away as-is. Thanks!

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Prettier package not actually being cached 777677671  
753653033 https://github.com/simonw/datasette/issues/1169#issuecomment-753653033 https://api.github.com/repos/simonw/datasette/issues/1169 MDEyOklzc3VlQ29tbWVudDc1MzY1MzAzMw== simonw 9599 2021-01-03T17:52:53Z 2021-01-03T17:52:53Z OWNER

Oh that's so frustrating! I was worried about that - I spotted a few runs that seemed faster and hoped that it meant that the package was coming out of the ~/.npm cache, but evidently that's not the case.

You've convinced me that Datasette itself should have a package.json - the Dependabot argument is a really good one.

But... I'd really love to figure out a general pattern for using npx scripts in GitHub Actions workflows in a cache-friendly way. I have plenty of other projects that I'd love to run Prettier or Uglify or puppeteer-cli in without adding a package.json to them.

Any ideas? The best I can think of is for the workflow itself to write out a package.json file (using echo '{ ... }' > package.json) as part of the run - that way the cache should work (I think) but I don't get a misleading package.json file sitting in the repo.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Prettier package not actually being cached 777677671  
753570710 https://github.com/simonw/datasette/issues/983#issuecomment-753570710 https://api.github.com/repos/simonw/datasette/issues/983 MDEyOklzc3VlQ29tbWVudDc1MzU3MDcxMA== simonw 9599 2021-01-03T05:29:56Z 2021-01-03T05:29:56Z OWNER

I thought about using browser events, but they don't quite match the API that I'm looking to provide. In particular, the great thing about Pluggy is that if you have multiple handlers registered for a specific plugin hook each of those handlers can return a value, and Pluggy will combine those values into a list of replies.

This is great for things like plugin hooks that add extra menu items - each plugin can return a menu item (maybe as a label/URL/click-callback object) and the calling code can then add all of those items to the menu. See https://docs.datasette.io/en/stable/plugin_hooks.html#table-actions-datasette-actor-database-table for a Python example.

I'm on the fence about relying on JavaScript modules. I need to think about browser compatibility for them - but I'm already commited to requiring support for () => {} arrow functions so maybe I'm committed to module support too already?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
JavaScript plugin hooks mechanism similar to pluggy 712260429  
753568428 https://github.com/simonw/datasette/issues/1160#issuecomment-753568428 https://api.github.com/repos/simonw/datasette/issues/1160 MDEyOklzc3VlQ29tbWVudDc1MzU2ODQyOA== simonw 9599 2021-01-03T05:02:32Z 2021-01-03T05:02:32Z OWNER

Should this command include a --fts option for configuring full-text search on one-or-more columns?

I thought about doing that for sqlite-utils insert in https://github.com/simonw/sqlite-utils/issues/202 and decided not to because of the need to include extra options covering the FTS version, porter stemming options and whether or not to create triggers.

But maybe I can set sensible defaults for that with datasette insert ... -f title -f body? Worth thinking about a bit more.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
"datasette insert" command and plugin hook 775666296  
753568264 https://github.com/simonw/sqlite-utils/issues/202#issuecomment-753568264 https://api.github.com/repos/simonw/sqlite-utils/issues/202 MDEyOklzc3VlQ29tbWVudDc1MzU2ODI2NA== simonw 9599 2021-01-03T05:00:24Z 2021-01-03T05:00:24Z OWNER

I'm not going to implement this, because it actually needs several additional options that already exist on sqlite-utils enable-fts: --fts4 Use FTS4 --fts5 Use FTS5 --tokenize TEXT Tokenizer to use, e.g. porter --create-triggers Create triggers to update the FTS tables when the parent table changes. I'd rather not add all four of those options to sqlite-utils insert just to support this shortcut.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils insert -f colname - for configuring full-text search 738514367  
753567969 https://github.com/simonw/sqlite-utils/issues/202#issuecomment-753567969 https://api.github.com/repos/simonw/sqlite-utils/issues/202 MDEyOklzc3VlQ29tbWVudDc1MzU2Nzk2OQ== simonw 9599 2021-01-03T04:55:17Z 2021-01-03T04:55:43Z OWNER

The long version of this can be --fts, same as in csvs-to-sqlite.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils insert -f colname - for configuring full-text search 738514367  
753567932 https://github.com/simonw/sqlite-utils/pull/203#issuecomment-753567932 https://api.github.com/repos/simonw/sqlite-utils/issues/203 MDEyOklzc3VlQ29tbWVudDc1MzU2NzkzMg== simonw 9599 2021-01-03T04:54:43Z 2021-01-03T04:54:43Z OWNER

Another option: expand the ForeignKey object to have .columns and .other_columns properties in addition to the existing .column and .other_column properties. These new plural properties would always return a tuple, which would be a one-item tuple for a non-compound-foreign-key.

The question then is what should .column and .other_column return for compound foreign keys?

I'd be inclined to say they should return None - which would trigger errors in code that encounters a compound foreign key for the first time, but those errors would at least be a strong indicator as to what had gone wrong.

We can label .column and .other_column as deprecated and then remove them in sqlite-utils 4.0.

Since this would still be a breaking change in some minor edge-cases I'm thinking maybe 4.0 needs to happen in order to land this feature. I'm not opposed to doing that, I was just hoping it might be avoidable.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
changes to allow for compound foreign keys 743384829  
753567744 https://github.com/simonw/sqlite-utils/pull/203#issuecomment-753567744 https://api.github.com/repos/simonw/sqlite-utils/issues/203 MDEyOklzc3VlQ29tbWVudDc1MzU2Nzc0NA== simonw 9599 2021-01-03T04:51:44Z 2021-01-03T04:51:44Z OWNER

One way that this could avoid a breaking change would be to have fk.column and fk.other_column remain as strings for non-compound-foreign-keys, but turn into tuples for a compound foreign key.

This is a bit of an ugly API design, and it could still break existing code that encounters a compound foreign key for the first time - but it would leave code working for the more common case of a non-compound-foreign-key.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
changes to allow for compound foreign keys 743384829  
753567508 https://github.com/simonw/sqlite-utils/pull/203#issuecomment-753567508 https://api.github.com/repos/simonw/sqlite-utils/issues/203 MDEyOklzc3VlQ29tbWVudDc1MzU2NzUwOA== simonw 9599 2021-01-03T04:48:17Z 2021-01-03T04:48:17Z OWNER

Sorry for taking so long to review this!

This approach looks great to me - being able to optionally pass a tuple anywhere the API currently expects a column is smart, and it's consistent with how the pk= parameter works elsewhere.

There's just one problem I can see with this: the way it changes the ForeignKey(...) interface to always return a tuple for .column and .other_column, even if that tuple only contains a single item.

This represents a breaking change to the existing API - any code that expects ForeignKey.column to be a single string (which is any code that has been written against that) will break.

As such, I'd have to bump the major version of sqlite-utils to 4.0 in order to ship this.

Ideally I'd like to make this change in a way that doesn't represent an API compatibility break. I need to think a bit harder about how that might be achieved.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
changes to allow for compound foreign keys 743384829  
753566184 https://github.com/simonw/sqlite-utils/issues/217#issuecomment-753566184 https://api.github.com/repos/simonw/sqlite-utils/issues/217 MDEyOklzc3VlQ29tbWVudDc1MzU2NjE4NA== simonw 9599 2021-01-03T04:27:38Z 2021-01-03T04:27:38Z OWNER

Documented here: https://sqlite-utils.datasette.io/en/latest/python-api.html#quoting-strings-for-use-in-sql

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Rename .escape() to .quote() 777543336  
753566156 https://github.com/simonw/sqlite-utils/issues/216#issuecomment-753566156 https://api.github.com/repos/simonw/sqlite-utils/issues/216 MDEyOklzc3VlQ29tbWVudDc1MzU2NjE1Ng== simonw 9599 2021-01-03T04:27:14Z 2021-01-03T04:27:14Z OWNER

Documented here: https://sqlite-utils.datasette.io/en/latest/python-api.html#introspection

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
database.triggers_dict introspection property 777540352  
753563757 https://github.com/simonw/sqlite-utils/issues/218#issuecomment-753563757 https://api.github.com/repos/simonw/sqlite-utils/issues/218 MDEyOklzc3VlQ29tbWVudDc1MzU2Mzc1Nw== simonw 9599 2021-01-03T03:49:51Z 2021-01-03T03:49:51Z OWNER

Documentation: https://sqlite-utils.datasette.io/en/latest/cli.html#listing-triggers

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
"sqlite-utils triggers" command 777560474  

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 526.348ms · About: github-to-sqlite