civisanalytics / civis-python

Civis API Python Client
BSD 3-Clause "New" or "Revised" License
34 stars 26 forks source link

ENH SQL CLI #319

Closed stephen-hoover closed 5 years ago

stephen-hoover commented 5 years ago

Provide options to run SQL commands through the CLI. Users can either run a command with short output from a file or from the command line, or download the results of a query.

stephen-hoover commented 5 years ago

I'm very open to design/API feedback, up to and including YAGNI. It seemed like a "run my SQL file" function would be helpful, and it was very quick to write. A potential future feature here is a "non-blocking" option flag or a simplified output flag to help with bash chaining, but I figured I'd see if anyone was interested in the basic version first.

stephen-hoover commented 5 years ago
  1. Can we simplify into a single cli call with options / flags?

You mean something like civis sql [DATABASE] [FILENAME] for the query, and civis sql -d [OUTPUT_FILE] [DATABASE] [FILENAME] for downloading? I could make that change, but I don't see it as simpler. Your point 3 is about handling the difference between queries and scripts -- I think that the present setup makes that reasonably clear. I added more help text to try to make it even more explicit. I could maybe add a "..." at the end when we get the maximum number of rows back if you think that would help. On scripts with no output -- I'm not really worried about that. It would execute but raise an exception, right? If someone tries to download the result of a GRANT query, I'm not sure what they expect. In the current code, it runs, then loudly complains that it can't download anything.

keithing commented 5 years ago

I could make that change, but I don't see it as simpler.

I was imagining we might emulate psql, especially with -c, -f, -o and -d. What's nice about this is that you can run civis sql --help and see all the options, whereas with 3 commands there is an issue of discoverability. We could have some sort of logic that query_civis is used for all queries except when an output file is specified with -o and then we use civis_to_csv.

stephen-hoover commented 5 years ago

Oh, I see. Yes, I like that. I could make that change for next week.

On Wed, Aug 21, 2019 at 3:57 PM Keith Ingersoll notifications@github.com wrote:

I could make that change, but I don't see it as simpler.

I was imagining we might emulate psql https://www.postgresql.org/docs/9.2/app-psql.html, especially with -c, -f, -o and -d. What's nice about this is that you can run civis sql --help and see all the options, whereas with 3 commands there is an issue of discoverability. We could have some sort of logic that query_civis is used for all queries except when an output file is specified with -o and then we use civis_to_csv.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/civisanalytics/civis-python/pull/319?email_source=notifications&email_token=AB7YBCPKUXFNIFBRLCACUDDQFWTZ3A5CNFSM4INBXWR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD43DIAA#issuecomment-523645952, or mute the thread https://github.com/notifications/unsubscribe-auth/AB7YBCM22ZOOFPTY5JD3JQTQFWTZ3ANCNFSM4INBXWRQ .

-- Stephen Hoover Civis | Analytics Lead Data Scientist

stephen-hoover commented 5 years ago

@keithing , I updated the UI as per your request.

stephen-hoover commented 5 years ago

@keithing , I made the stderr change you requested.