prql icon indicating copy to clipboard operation
prql copied to clipboard

Add CLI

Open max-sixty opened this issue 4 years ago • 3 comments

It would be good to have a CLI which can take PRQL and do things like:

  • Produce SQL, using writer.rs (most important, it'd be fine if this is all it does tbh)
  • Produce an AST, using parser.rs
  • Produce a parse tree, using ast.rs

This will provide the basis of the tool for producing SQL, and provide a simple entry point for people to see intermediate data.

If anyone wants to take this on, please feel free to start with a very small PR.

max-sixty avatar Feb 20 '22 20:02 max-sixty

There probably should be a --flavour flag which allows you to specify which DBMS (Postgress, MariaDB, etc) you're targeting. This would supercede the flavour value given in a PRQL file.

Something to consider is wether we want to be able to automatically query a DBMS. This means there would be two ways to interact with PRQL

  1. prql --flavour psql --host localhost --user user --password strongpass query.prql
  2. prql -o query.sql query.prql

Where the second workflow is specifying a file to output the generated SQL file to.

Another option may be to print the generated SQL to stdout if no -o or --host is set. This would be the easiest route for v1 if the other options were put on the roadmap as this would allow piping into the sql program.

I'm not sure "flavour" is the right name for the flag and I'm open to suggestions.

danjones1618 avatar Feb 22 '22 01:02 danjones1618

Yes, I think we can start with something fairly basic that gives an interface to what's currently available — fine to use stdin / stdout, with the option of supplying file names too.

I agree we could add dialects / flavors (and even direct querying) later.

Let me know if you want to take a swing at this @danjones1618

max-sixty avatar Feb 22 '22 06:02 max-sixty

I think direct querying could be a game changer! That might just be the killer app for PRQL.

qorrect avatar Feb 22 '22 14:02 qorrect