home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

24 rows where "updated_at" is on date 2021-06-16 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 6

  • Idea: import CSV to memory, run SQL, export in a single command 13
  • sqlite-utils memory command for directly querying CSV/JSON data 6
  • row.update() or row.pk 2
  • sqlite-utils insert: options for column types 1
  • Cannot set type JSON 1
  • Enable code coverage 1

user 1

  • simonw · 24 ✖

author_association 1

  • OWNER 24
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
862617165 https://github.com/simonw/sqlite-utils/issues/275#issuecomment-862617165 https://api.github.com/repos/simonw/sqlite-utils/issues/275 MDEyOklzc3VlQ29tbWVudDg2MjYxNzE2NQ== simonw 9599 2021-06-16T18:34:51Z 2021-06-16T18:34:51Z OWNER

Also use this: https://github.com/simonw/datasette/blob/83e9c8bc7585dcc62f200e37c2daefcd669ee05e/codecov.yml

And add a badge, as seen on https://github.com/simonw/asgi-csrf

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Enable code coverage 922955697  
862605436 https://github.com/simonw/sqlite-utils/pull/273#issuecomment-862605436 https://api.github.com/repos/simonw/sqlite-utils/issues/273 MDEyOklzc3VlQ29tbWVudDg2MjYwNTQzNg== simonw 9599 2021-06-16T18:19:05Z 2021-06-16T18:19:05Z OWNER

--attach documentation: https://github.com/simonw/sqlite-utils/blob/192dc2c5b73bd836ab8e2e5fed4b36c6ea02f250/docs/cli.rst#joining-in-memory-data-against-existing-databases-using-attach

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils memory command for directly querying CSV/JSON data 922099793  
862494864 https://github.com/simonw/sqlite-utils/issues/267#issuecomment-862494864 https://api.github.com/repos/simonw/sqlite-utils/issues/267 MDEyOklzc3VlQ29tbWVudDg2MjQ5NDg2NA== simonw 9599 2021-06-16T15:51:28Z 2021-06-16T16:26:15Z OWNER

I did add a slightly clumsy mechanism recently to help a bit here though: the pks_and_rows_where() method: https://sqlite-utils.datasette.io/en/stable/python-api.html#listing-rows-with-their-primary-keys

More details in the issue for that feature: #240

The idea here is that if you want to call update you need the primary key for the row - so you can do this:

python for pk, row in db["sometable"].pks_and_rows_where(): db["sometable"].update(pk, {"modified": 1}") The pk may end up as a single value or a tuple depending on if the table has a compound primary key - but you don't need to worry about that if you use this method as it will return the correct primary key value for you.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
row.update() or row.pk 915421499  
862495803 https://github.com/simonw/sqlite-utils/issues/131#issuecomment-862495803 https://api.github.com/repos/simonw/sqlite-utils/issues/131 MDEyOklzc3VlQ29tbWVudDg2MjQ5NTgwMw== simonw 9599 2021-06-16T15:52:33Z 2021-06-16T15:52:33Z OWNER

I like -t or --type for this.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils insert: options for column types 675753042  
862493179 https://github.com/simonw/sqlite-utils/issues/267#issuecomment-862493179 https://api.github.com/repos/simonw/sqlite-utils/issues/267 MDEyOklzc3VlQ29tbWVudDg2MjQ5MzE3OQ== simonw 9599 2021-06-16T15:49:13Z 2021-06-16T15:49:13Z OWNER

The big challenge here is that the rows returned by this library aren't objects, they are Python dictionaries - so adding methods to them isn't possible without changing the type that is returned by these methods.

Part of the philosophy of the library is that it should make it as easy as possible to round-trip between Python dictionaries and SQLite table data, so I don't think adding methods like this is going to fit.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
row.update() or row.pk 915421499  
862491721 https://github.com/simonw/sqlite-utils/issues/270#issuecomment-862491721 https://api.github.com/repos/simonw/sqlite-utils/issues/270 MDEyOklzc3VlQ29tbWVudDg2MjQ5MTcyMQ== simonw 9599 2021-06-16T15:47:06Z 2021-06-16T15:47:06Z OWNER

SQLite doesn't have a JSON column type - it has JSON processing functions, but they operate against TEXT columns - so there's nothing I can do here unfortunately.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Cannot set type JSON 919314806  
862491016 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862491016 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjQ5MTAxNg== simonw 9599 2021-06-16T15:46:13Z 2021-06-16T15:46:13Z OWNER

Columns from data imported from CSV in this way is currently treated as TEXT, which means numeric sorts and suchlike won't work as people might expect. It would be good to do automatic type detection here, see #179.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
862485408 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862485408 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjQ4NTQwOA== simonw 9599 2021-06-16T15:38:58Z 2021-06-16T15:39:28Z OWNER

Also sqlite-utils memory reflects the existing sqlite-utils :memory: mechanism, which is a point in its favour.

And it helps emphasize that the file you are querying will be loaded into memory, so probably don't try this against a 1GB CSV file.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
862484557 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862484557 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjQ4NDU1Nw== simonw 9599 2021-06-16T15:37:51Z 2021-06-16T15:38:34Z OWNER

I wonder if there's a better name for this than sqlite-utils memory?

  • sqlite-utils memory hello.csv "select * from hello"
  • sqlite-utils mem hello.csv "select * from hello"
  • sqlite-utils temp hello.csv "select * from hello"
  • sqlite-utils adhoc hello.csv "select * from hello"
  • sqlite-utils scratch hello.csv "select * from hello"

I think memory is best. I don't like the others, except for scratch which is OK.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
862479704 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862479704 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjQ3OTcwNA== simonw 9599 2021-06-16T15:31:31Z 2021-06-16T15:31:31Z OWNER

Plus, could I make this change to sqlite-utils query without breaking backwards compatibility? Adding a new sqlite-utils memory command is completely safe from that perspective.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
862478881 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862478881 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjQ3ODg4MQ== simonw 9599 2021-06-16T15:30:24Z 2021-06-16T15:30:24Z OWNER

But... sqlite-utils my.csv "select * from my" is a much more compelling initial experience than sqlite-utils memory my.csv "select * from my".

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
862475685 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862475685 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjQ3NTY4NQ== simonw 9599 2021-06-16T15:26:19Z 2021-06-16T15:29:38Z OWNER

Here's a radical idea: what if I combined sqlite-utils memory into sqlite-utils query?

The trick here would be to detect if the arguments passed on the command-line refer to SQLite databases or if they refer to CSV/JSON data that should be imported into temporary tables.

Detecting a SQLite database file is actually really easy - they all start with the same binary string: ```pycon

open("my.db", "rb").read(100) b'SQLite format 3\x00... `` (Need to carefully check that a CSV file withSQLite format 3` as the first column name doesn't accidentally get interpreted as a SQLite DB though).

So then what would the semantics of sqlite-utils query (which is also the default command) be?

  • sqlite-utils mydb.db "select * from x"
  • sqlite-utils my.csv "select * from my"
  • sqlite-utils mydb.db my.csv "select * from mydb.x join my on ..." - this is where it gets weird. We can't import the CSV data directly into mpdb.db - it's suppose to go into the in-memory database - so now we need to start using database aliases like mydb.x because we passed at least one other file?

The complexity here is definitely in the handling of a combination of SQLite database files and CSV filenames. Also, sqlite-utils query doesn't accept multiple filenames at the moment, so that will change.

I'm not 100% sold on this as being better than having a separate sqlite-utils memory command, as seen in #273.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
862046009 https://github.com/simonw/sqlite-utils/pull/273#issuecomment-862046009 https://api.github.com/repos/simonw/sqlite-utils/issues/273 MDEyOklzc3VlQ29tbWVudDg2MjA0NjAwOQ== simonw 9599 2021-06-16T05:15:38Z 2021-06-16T05:15:38Z OWNER

I'm going to add a --encoding option - it will affect ALL CSV input files, so if you have CSV files with different encodings you'll need to sort that mess out yourself (likely by importing each CSV file separately into a database using sqlite-utils insert with different --encoding values).

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils memory command for directly querying CSV/JSON data 922099793  
862045639 https://github.com/simonw/sqlite-utils/pull/273#issuecomment-862045639 https://api.github.com/repos/simonw/sqlite-utils/issues/273 MDEyOklzc3VlQ29tbWVudDg2MjA0NTYzOQ== simonw 9599 2021-06-16T05:14:38Z 2021-06-16T05:14:38Z OWNER

Can't share much code though since a bunch of that insert stuff is specific to that command - showing progress bars, returning errors on illegal option combinations etc.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils memory command for directly querying CSV/JSON data 922099793  
862045438 https://github.com/simonw/sqlite-utils/pull/273#issuecomment-862045438 https://api.github.com/repos/simonw/sqlite-utils/issues/273 MDEyOklzc3VlQ29tbWVudDg2MjA0NTQzOA== simonw 9599 2021-06-16T05:14:00Z 2021-06-16T05:14:00Z OWNER

I should probably refactor the CSV/JSON/loading stuff into a function in utils.py in order to share some of the implementation with the existing sqlite-utils insert code: https://github.com/simonw/sqlite-utils/blob/287cdcae8908916687f2ecccc87c38549d004ac6/sqlite_utils/cli.py#L691-L734

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils memory command for directly querying CSV/JSON data 922099793  
862043974 https://github.com/simonw/sqlite-utils/pull/273#issuecomment-862043974 https://api.github.com/repos/simonw/sqlite-utils/issues/273 MDEyOklzc3VlQ29tbWVudDg2MjA0Mzk3NA== simonw 9599 2021-06-16T05:10:12Z 2021-06-16T05:10:12Z OWNER

I can stop promoting :memory: here and promote memory instead:

https://github.com/simonw/sqlite-utils/blob/c7234cae8336b8525034e8f917d82dd0699abd42/docs/cli.rst#L83-L86

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils memory command for directly querying CSV/JSON data 922099793  
862042110 https://github.com/simonw/sqlite-utils/pull/273#issuecomment-862042110 https://api.github.com/repos/simonw/sqlite-utils/issues/273 MDEyOklzc3VlQ29tbWVudDg2MjA0MjExMA== simonw 9599 2021-06-16T05:05:51Z 2021-06-16T05:06:11Z OWNER

Initial documentation is here: https://github.com/simonw/sqlite-utils/blob/c7234cae8336b8525034e8f917d82dd0699abd42/docs/cli.rst#running-queries-directly-against-csv-data

It only talks about CSV at the moment - needs to be updated to mention JSON too once that is implemented.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
sqlite-utils memory command for directly querying CSV/JSON data 922099793  
862040971 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862040971 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjA0MDk3MQ== simonw 9599 2021-06-16T05:02:56Z 2021-06-16T05:02:56Z OWNER

Moving this to a PR.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
862040906 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862040906 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjA0MDkwNg== simonw 9599 2021-06-16T05:02:47Z 2021-06-16T05:02:47Z OWNER

Got a prototype working! % curl -s 'https://fivethirtyeight.datasettes.com/polls/president_approval_polls.csv?_size=max&_stream=1' | sqlite-utils memory - 'select * from t limit 5' --nl {"rowid": "1", "question_id": "139304", "poll_id": "74225", "state": "", "politician_id": "11", "politician": "Donald Trump", "pollster_id": "568", "pollster": "YouGov", "sponsor_ids": "352", "sponsors": "Economist", "display_name": "YouGov", "pollster_rating_id": "391", "pollster_rating_name": "YouGov", "fte_grade": "B", "sample_size": "1500", "population": "a", "population_full": "a", "methodology": "Online", "start_date": "1/16/21", "end_date": "1/19/21", "sponsor_candidate": "", "tracking": "", "created_at": "1/20/21 10:18", "notes": "", "url": "https://docs.cdn.yougov.com/y9zsit5bzd/weeklytrackingreport.pdf", "source": "538", "yes": "42.0", "no": "53.0"} {"rowid": "2", "question_id": "139305", "poll_id": "74225", "state": "", "politician_id": "11", "politician": "Donald Trump", "pollster_id": "568", "pollster": "YouGov", "sponsor_ids": "352", "sponsors": "Economist", "display_name": "YouGov", "pollster_rating_id": "391", "pollster_rating_name": "YouGov", "fte_grade": "B", "sample_size": "1155", "population": "rv", "population_full": "rv", "methodology": "Online", "start_date": "1/16/21", "end_date": "1/19/21", "sponsor_candidate": "", "tracking": "", "created_at": "1/20/21 10:18", "notes": "", "url": "https://docs.cdn.yougov.com/y9zsit5bzd/weeklytrackingreport.pdf", "source": "538", "yes": "44.0", "no": "55.0"} {"rowid": "3", "question_id": "139306", "poll_id": "74226", "state": "", "politician_id": "11", "politician": "Donald Trump", "pollster_id": "23", "pollster": "American Research Group", "sponsor_ids": "", "sponsors": "", "display_name": "American Research Group", "pollster_rating_id": "9", "pollster_rating_name": "American Research Group", "fte_grade": "B", "sample_size": "1100", "population": "a", "population_full": "a", "methodology": "Live Phone", "start_date": "1/16/21", "end_date": "1/19/21", "sponsor_candidate": "", "tracking": "", "created_at": "1/20/21 10:18", "notes": "", "url": "https://americanresearchgroup.com/economy/", "source": "538", "yes": "30.0", "no": "66.0"} {"rowid": "4", "question_id": "139307", "poll_id": "74226", "state": "", "politician_id": "11", "politician": "Donald Trump", "pollster_id": "23", "pollster": "American Research Group", "sponsor_ids": "", "sponsors": "", "display_name": "American Research Group", "pollster_rating_id": "9", "pollster_rating_name": "American Research Group", "fte_grade": "B", "sample_size": "990", "population": "rv", "population_full": "rv", "methodology": "Live Phone", "start_date": "1/16/21", "end_date": "1/19/21", "sponsor_candidate": "", "tracking": "", "created_at": "1/20/21 10:18", "notes": "", "url": "https://americanresearchgroup.com/economy/", "source": "538", "yes": "29.0", "no": "67.0"} {"rowid": "5", "question_id": "139298", "poll_id": "74224", "state": "", "politician_id": "11", "politician": "Donald Trump", "pollster_id": "1528", "pollster": "AtlasIntel", "sponsor_ids": "", "sponsors": "", "display_name": "AtlasIntel", "pollster_rating_id": "546", "pollster_rating_name": "AtlasIntel", "fte_grade": "B/C", "sample_size": "5188", "population": "a", "population_full": "a", "methodology": "Online", "start_date": "1/15/21", "end_date": "1/19/21", "sponsor_candidate": "", "tracking": "", "created_at": "1/19/21 21:52", "notes": "", "url": "https://projects.fivethirtyeight.com/polls/20210119_US_Atlas2.pdf", "source": "538", "yes": "44.6", "no": "53.9"}

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
862018937 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-862018937 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MjAxODkzNw== simonw 9599 2021-06-16T03:59:28Z 2021-06-16T04:00:05Z OWNER

Mainly for debugging purposes it would be useful to be able to save the created in-memory database back to a file again later. This could be done with:

sqlite-utils memory blah.csv --save saved.db

Can use .iterdump() to implement this: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.iterdump

Maybe instead (or as-well-as) offer --dump which dumps out the SQL from that.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
861989987 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-861989987 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MTk4OTk4Nw== simonw 9599 2021-06-16T02:34:21Z 2021-06-16T02:34:21Z OWNER

The documentation already covers this $ sqlite-utils :memory: "select sqlite_version()" [{"sqlite_version()": "3.29.0"}] https://sqlite-utils.datasette.io/en/latest/cli.html#running-queries-and-returning-json

sqlite-utils memory "select sqlite_version()" is a little bit more intuitive than that.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
861987651 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-861987651 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MTk4NzY1MQ== simonw 9599 2021-06-16T02:27:20Z 2021-06-16T02:27:20Z OWNER

Solution: sqlite-utils memory - attempts to detect the input based on if it starts with a { or [ (likely JSON) or if it doesn't use the csv.Sniffer() mechanism. Or you can use sqlite-utils memory -:csv to specifically indicate the type of input.

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
861985944 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-861985944 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MTk4NTk0NA== simonw 9599 2021-06-16T02:22:52Z 2021-06-16T02:22:52Z OWNER

Another option: allow an optional :suffix specifying the type of the file. If this is missing we detect based on the filename.

sqlite-utils memory somefile:csv "select * from somefile"

One catch: how to treat - for standard input?

cat blah.csv | sqlite-utils memory - "select * from stdin"

That's fine for CSV, but what about TSV or JSON or nl-JSON? Maybe this:

cat blah.csv | sqlite-utils memory -:json "select * from stdin"

Bit weird though. The alternative would be to support this:

cat blah.csv | sqlite-utils memory --load-csv -

But that's verbose compared to the version without the long --load-x option.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  
861984707 https://github.com/simonw/sqlite-utils/issues/272#issuecomment-861984707 https://api.github.com/repos/simonw/sqlite-utils/issues/272 MDEyOklzc3VlQ29tbWVudDg2MTk4NDcwNw== simonw 9599 2021-06-16T02:19:48Z 2021-06-16T02:19:48Z OWNER

This is going to need to be a separate command, for relatively non-obvious reasons.

sqlite-utils blah.db "select * from x"

Is equivalent to this, because query is the default sub-command:

sqlite-utils query blah.db "select * from x"

But... this means that making the filename optional doesn't actually work - because then this is ambiguous:

sqlite-utils --load-csv blah.csv "select * from blah"

So instead, I'm going to add a new sub-command. I'm currently thinking memory to reflect that this command operates on an in-memory database:

sqlite-utils memory --load-csv blah.csv "select * from blah"

I still think I need to use --load-csv rather than --csv because one interesting use-case for this is loading in CSV and converting it to JSON, or vice-versa.

Another option: allow multiple arguments which are filenames, and use the extension (or sniff the content) to decide what to do with them:

sqlite-utils memory blah.csv foo.csv "select * from foo join blah on ..."

This would require the last positional argument to always be a SQL query, and would treat all other positional arguments as files that should be imported into memory.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Idea: import CSV to memory, run SQL, export in a single command 921878733  

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