simonw / google-drive-to-sqlite

Create a SQLite database containing metadata from Google Drive
https://datasette.io/tools/google-drive-to-sqlite
Apache License 2.0
152 stars 13 forks source link

`--sql` option for `download` and `export` commands #38

Open simonw opened 2 years ago

simonw commented 2 years ago

twitter-to-sqlite has this: https://datasette.io/tools/twitter-to-sqlite#user-content-providing-input-from-a-sql-query-with---sql-and---attach

$ twitter-to-sqlite users-lookup my.db \
    --sql="select followed_id from following where followed_id not in (
        select id from users)" --ids

Some kind of equivalent for the download and export commands would be neat.

simonw commented 2 years ago

Maybe something like this:

google-drive-to-sqlite download --db files.db \
  --sql "select id from drive_files where mimeType = 'application/pdf'"

The --db option there is a tiny bit inconsistent with other commands where the database is the first argument, but since download is usually used without a database I think it makes sense.

simonw commented 2 years ago

The SQL query can return the following columns:

I thought about also including format to allow export commands to use a different export format for each file, but this would conflict with the required first argument to that command.

simonw commented 2 years ago

I think just having --sql but making it take two arguments - filename and query - would be better:

google-drive-to-sqlite download \
  --sql files.db "select id from drive_files where mimeType = 'application/pdf'"