home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

3 rows where author_association = "OWNER" and issue = 1429029604 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 3

issue 1

  • Make `cursor.rowcount` accessible (wontfix) · 3 ✖

author_association 1

  • OWNER · 3 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
1298879701 https://github.com/simonw/sqlite-utils/issues/506#issuecomment-1298879701 https://api.github.com/repos/simonw/sqlite-utils/issues/506 IC_kwDOCGYnMM5Na1TV simonw 9599 2022-11-01T17:37:13Z 2022-11-01T17:37:13Z OWNER

The question I was originally trying to answer here was this: how many rows were actually inserted by that call to .insert_all()?

I don't know that .rowcount would ever be useful here, since the "correct" answer depends on other factors - had I determined to ignore or replace records with a primary key that matches an existing record for example?

So I think if people need rowcount they can get it by using a cursor directly.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Make `cursor.rowcount` accessible (wontfix) 1429029604  
1298877872 https://github.com/simonw/sqlite-utils/issues/506#issuecomment-1298877872 https://api.github.com/repos/simonw/sqlite-utils/issues/506 IC_kwDOCGYnMM5Na02w simonw 9599 2022-11-01T17:35:30Z 2022-11-01T17:35:30Z OWNER

This may not make sense.

First, .last_rowid is a property on table - but that doesn't make sense for rowcount since it should clearly be a property on the database itself (you can run a query directly using db.execute() without going through a Table object).

So I tried this prototype:

`diff diff --git a/docs/python-api.rst b/docs/python-api.rst index 206e5e6..78d3a8d 100644 --- a/docs/python-api.rst +++ b/docs/python-api.rst @@ -186,6 +186,15 @@ Thedb.query(sql)`` function executes a SQL query and returns an iterator over # {'name': 'Cleo'} # {'name': 'Pancakes'}

+After executing a query the db.rowcount property on that database instance will reflect the number of rows affected by any insert, update or delete operations performed by that query: + +.. code-block:: python + + db = Database(memory=True) + db["dogs"].insert_all([{"name": "Cleo"}, {"name": "Pancakes"}]) + print(db.rowcount) + # Outputs: 2 + .. _python_api_execute:

db.execute(sql, params) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index a06f4b7..c19c2dd 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -294,6 +294,8 @@ class Database:

 _counts_table_name = "_counts"
 use_counts_table = False
  • Number of rows inserted, updated or deleted

  • rowcount: Optional[int] = None

    def init( self, @@ -480,9 +482,11 @@ class Database: if self._tracer: self._tracer(sql, parameters) if parameters is not None: - return self.conn.execute(sql, parameters) + cursor = self.conn.execute(sql, parameters) else: - return self.conn.execute(sql) + cursor = self.conn.execute(sql) + self.rowcount = cursor.rowcount + return cursor

    def executescript(self, sql: str) -> sqlite3.Cursor: """ But this happens:pycon

    from sqlite_utils import Database db = Database(memory=True) db["dogs"].insert_all([{"name": "Cleo"}, {"name": "Pancakes"}])

<Table dogs (name)> >>> db.rowcount -1 ``` Turning on query tracing demonstrates why: ```pycon >>> db = Database(memory=True, tracer=print) PRAGMA recursive_triggers=on; None >>> db["dogs"].insert_all([{"name": "Cleo"}, {"name": "Pancakes"}]) select name from sqlite_master where type = 'view' None select name from sqlite_master where type = 'table' None select name from sqlite_master where type = 'view' None CREATE TABLE [dogs] ( [name] TEXT ); None select name from sqlite_master where type = 'view' None INSERT INTO [dogs] ([name]) VALUES (?), (?); ['Cleo', 'Pancakes'] select name from sqlite_master where type = 'table' None select name from sqlite_master where type = 'table' None PRAGMA table_info([dogs]) None <Table dogs (name)> >>> ``` The `.insert_all()` function does a bunch of other queries too, so `.rowcount` is quickly over-ridden by the same result from extra queries that it executed.
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Make `cursor.rowcount` accessible (wontfix) 1429029604  
1296358636 https://github.com/simonw/sqlite-utils/issues/506#issuecomment-1296358636 https://api.github.com/repos/simonw/sqlite-utils/issues/506 IC_kwDOCGYnMM5NRNzs simonw 9599 2022-10-30T21:52:11Z 2022-10-30T21:52:11Z OWNER

This could work in a similar way to db.insert(...).last_rowid.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Make `cursor.rowcount` accessible (wontfix) 1429029604  

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