dbnet-io / dbnet

dbNet is a web-based database client using Go as a backend, and React as front-end
https://docs.dbnet.io
GNU Affero General Public License v3.0
15 stars 1 forks source link

cli: dbnet exec output as CSV or JSON to screen or file ? #9

Closed gedw99 closed 1 year ago

gedw99 commented 1 year ago

At the moment i can't seem to run SQL and get an output to terminal of the actual data.

Whats your game plan / roadmap here if i may ask ?

here is my little test case:

dbnet exec SQLITE --file select.sql
2023-07-10 16:06:44 INF Executing...
2023-07-10 16:06:44 INF Successful! Duration: 0 seconds

select-sql is simply:

SELECT * FROM positions;

The CLI help does not show any way to add args to tell it i want CSV or JSON out to screen or file....

dbnet exec -h
exec - execute a SQL query

  Usage:
    exec [conn]

  Positional Variables: 
    conn   The connection name (Required)
  Flags: 
       --version   Displays the program version string.
    -h --help      Displays help with available flag, subcommand, and positional value parameters.
       --query     The SQL query to execute
       --file      The SQL file to execute
flarco commented 1 year ago

Ah interesting, the exec sub-command was simply to execute SQLs without results (like updates). But I can add that. I usually use sling for that with sling run --src-conn SQLITE --src-stream 'select * from positions' --stdout. Sling will detect your env connections as well the same way.

But makes sense to actually output the results as CSV or JSON from CLI. Will add that as well.

For now you can do that with sling or from the frontend, there is a button on the right side, that says Export to CSV.

image
flarco commented 1 year ago

This is done. Feel free to try it!

$ ./dbnet exec
exec - execute a SQL query

  Usage:
    exec [conn]

  Positional Variables: 
    conn   The connection name (Required)
  Flags: 
       --version   Displays the program version string.
    -h --help      Displays help with available flag, subcommand, and positional value parameters.
       --query     The SQL query to execute
       --file      The SQL file to execute
       --csv       Output the results as CSV
       --json      Output the results as JSON Lines
gedw99 commented 1 year ago

Thanks @flarco

will try it .