home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

11 rows where author_association = "OWNER", issue = 770448622 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 · 11 ✖

issue 1

  • Database class mechanism for cross-connection in-memory databases · 11 ✖

author_association 1

  • OWNER · 11 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
767762551 https://github.com/simonw/datasette/issues/1151#issuecomment-767762551 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc2Nzc2MjU1MQ== simonw 9599 2021-01-26T19:07:44Z 2021-01-26T19:07:44Z OWNER

Mentioned in https://simonwillison.net/2021/Jan/25/datasette/

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747801751 https://github.com/simonw/datasette/issues/1151#issuecomment-747801751 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0NzgwMTc1MQ== simonw 9599 2020-12-18T01:03:39Z 2020-12-18T01:03:39Z OWNER

This feature is illustrated by the tests: https://github.com/simonw/datasette/blob/5e9895c67f08e9f42acedd3d6d29512ac446e15f/tests/test_internals_database.py#L469-L496

I added new documentation for the Datasette() constructor here as well: https://docs.datasette.io/en/latest/internals.html#database-ds-path-none-is-mutable-false-is-memory-false-memory-name-none

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747801084 https://github.com/simonw/datasette/issues/1151#issuecomment-747801084 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0NzgwMTA4NA== simonw 9599 2020-12-18T01:01:26Z 2020-12-18T01:01:26Z OWNER

I tested this with a one-off plugin and it worked!

```python from datasette import hookimpl from datasette.database import Database

@hookimpl def startup(datasette): datasette.add_database("statistics", Database( datasette, memory_name="statistics" )) `` This created a/statisticsdatabase when I randatasette` - and if I installed https://github.com/simonw/datasette-write I could then create tables in it which persisted until I restarted the server.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747784199 https://github.com/simonw/datasette/issues/1151#issuecomment-747784199 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0Nzc4NDE5OQ== simonw 9599 2020-12-18T00:09:36Z 2020-12-18T00:09:36Z OWNER

Is it possible to connect to a memory database in read-only mode?

file:foo?mode=memory&cache=shared&mode=ro isn't valid because it features mode= more than once.

https://stackoverflow.com/a/40548682 suggests using PRAGMA query_only on the connection instead.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747775245 https://github.com/simonw/datasette/issues/1151#issuecomment-747775245 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0Nzc3NTI0NQ== simonw 9599 2020-12-17T23:43:41Z 2020-12-17T23:56:27Z OWNER

I'm going to add an argument to the Database() constructor which means "connect to named in-memory database called X".

python db = Database(ds, memory_name="datasette")

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747779056 https://github.com/simonw/datasette/issues/1151#issuecomment-747779056 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0Nzc3OTA1Ng== simonw 9599 2020-12-17T23:55:57Z 2020-12-17T23:55:57Z OWNER

Wait I do use it - if you run datasette --memory - which is useful for trying things out in SQL that doesn't need to run against a table.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747775792 https://github.com/simonw/datasette/issues/1151#issuecomment-747775792 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0Nzc3NTc5Mg== simonw 9599 2020-12-17T23:45:20Z 2020-12-17T23:45:20Z OWNER

Do I use the current is_memory= boolean anywhere at the moment?

https://ripgrep.datasette.io/-/ripgrep?pattern=is_memory - doesn't look like it.

I may remove that feature, since it's not actually useful, and replace it with a mechanism for creating shared named memory databases instead.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747774855 https://github.com/simonw/datasette/issues/1151#issuecomment-747774855 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0Nzc3NDg1NQ== simonw 9599 2020-12-17T23:42:34Z 2020-12-17T23:42:34Z OWNER

This worked as a prototype: ```diff diff --git a/datasette/database.py b/datasette/database.py index 412e0c5..a90e617 100644 --- a/datasette/database.py +++ b/datasette/database.py @@ -24,11 +24,12 @@ connections = threading.local()

class Database: - def init(self, ds, path=None, is_mutable=False, is_memory=False): + def init(self, ds, path=None, is_mutable=False, is_memory=False, uri=None): self.ds = ds self.path = path self.is_mutable = is_mutable self.is_memory = is_memory + self.uri = uri self.hash = None self.cached_size = None self.cached_table_counts = None @@ -46,6 +47,8 @@ class Database: }

 def connect(self, write=False):
  • if self.uri:
  • return sqlite3.connect(self.uri, uri=True, check_same_thread=False) if self.is_memory: return sqlite3.connect(":memory:") # mode=ro or immutable=1? Then in `ipython`: from datasette.app import Datasette from datasette.database import Database ds = Datasette([]) db = Database(ds, uri="file:datasette?mode=memory&cache=shared", is_memory=True) await db.execute_write("create table foo (bar text)") await db.table_names()

Outputs ["foo"]

db2 = Database(ds, uri="file:datasette?mode=memory&cache=shared", is_memory=True) await db2.table_names()

Also outputs ["foo"]

```

```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747770581 https://github.com/simonw/datasette/issues/1151#issuecomment-747770581 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0Nzc3MDU4MQ== simonw 9599 2020-12-17T23:31:18Z 2020-12-17T23:32:07Z OWNER

This works in ipython: ``` In [1]: import sqlite3

In [2]: c1 = sqlite3.connect("file:datasette?mode=memory&cache=shared", uri=True)

In [3]: c2 = sqlite3.connect("file:datasette?mode=memory&cache=shared", uri=True)

In [4]: c1.executescript("CREATE TABLE hello (world TEXT)") Out[4]: <sqlite3.Cursor at 0x1104addc0>

In [5]: c1.execute("select * from sqlite_master").fetchall() Out[5]: [('table', 'hello', 'hello', 2, 'CREATE TABLE hello (world TEXT)')]

In [6]: c2.execute("select * from sqlite_master").fetchall() Out[6]: [('table', 'hello', 'hello', 2, 'CREATE TABLE hello (world TEXT)')]

In [7]: c3 = sqlite3.connect("file:datasette?mode=memory&cache=shared", uri=True)

In [9]: c3.execute("select * from sqlite_master").fetchall() Out[9]: [('table', 'hello', 'hello', 2, 'CREATE TABLE hello (world TEXT)')]

In [10]: c4 = sqlite3.connect("file:datasette?mode=memory", uri=True)

In [11]: c4.execute("select * from sqlite_master").fetchall() Out[11]: [] ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747770082 https://github.com/simonw/datasette/issues/1151#issuecomment-747770082 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0Nzc3MDA4Mg== simonw 9599 2020-12-17T23:29:53Z 2020-12-17T23:29:53Z OWNER

I'm going to try with file:datasette?mode=memory&cache=shared.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  
747769830 https://github.com/simonw/datasette/issues/1151#issuecomment-747769830 https://api.github.com/repos/simonw/datasette/issues/1151 MDEyOklzc3VlQ29tbWVudDc0Nzc2OTgzMA== simonw 9599 2020-12-17T23:29:08Z 2020-12-17T23:29:08Z OWNER

https://sqlite.org/inmemorydb.html

The database ceases to exist as soon as the database connection is closed. Every :memory: database is distinct from every other. So, opening two database connections each with the filename ":memory:" will create two independent in-memory databases.

[...]

The special ":memory:" filename also works when using URI filenames. For example:

 rc = sqlite3_open("file::memory:", &db);

[...]

However, the same in-memory database can be opened by two or more database connections as follows:

 rc = sqlite3_open("file::memory:?cache=shared", &db);

[...] If two or more distinct but shareable in-memory databases are needed in a single process, then the mode=memory query parameter can be used with a URI filename to create a named in-memory database:

rc = sqlite3_open("file:memdb1?mode=memory&cache=shared", &db);
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Database class mechanism for cross-connection in-memory databases 770448622  

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 408.705ms · About: github-to-sqlite
  • Sort ascending
  • Sort descending
  • Facet by this
  • Hide this column
  • Show all columns
  • Show not-blank rows