Charts in a script
A script can hold \chart as it holds any other meta command. Run the script with \i at the prompt, and usql draws each chart. A script that runs with -f writes a chart to a file, and draws no chart in the terminal.
This script, charts.sql, writes two charts to SVG files:
-- The sales of each month, and the cups of each hour.select month, coffee, tea, cocoa from sales order by month_no\chart title='Cups sold' file=sales.svgselect hour, cups from hours order by hour\chart title='Cups by hour' file=hours.svgThe script uses the tables of the gallery.
Run a script with \i
Section titled “Run a script with \i”\i runs a script at the prompt of usql:
\i charts.sqlusql writes sales.svg and hours.svg:
In a terminal that draws images, a script with the same \chart lines without file= draws each chart in place.
Run a script with -f
Section titled “Run a script with -f”-f runs the same script from the shell. \chart with file= writes each file:
usql -f charts.sql cafe.dbWhy -f draws no chart in the terminal
Section titled “Why -f draws no chart in the terminal”When usql runs a script from -f, or a command from -c, it turns the terminal graphics off, so that the escape codes of an image do not go to a pipe or a file. A \chart without file= then stops with an error:
error: \chart: graphics not supported in terminalTo draw the charts in the terminal, choose the protocol of your terminal on the command line with -U, such as kitty, iterm or sixel:
usql -U term_graphics=kitty -f charts.sql cafe.dbusql then draws each chart without file= to the standard output. Do this only when the output goes to your terminal. Terminal graphics says more about the protocols.