Client APIs
Usage
The DuckDB CLI can read both SQL commands and dot commands from an external file instead of the terminal using the `.read` command. This allows for a number of commands to be run in sequence and allows command sequences to be saved and reused.  
The `.read` command requires only one argument: the path to the file containing the SQL and/or commands to execute. After running the commands in the file, control will revert back to the terminal. Output from the execution of that file is governed by the same `.output` and `.once` commands that have been discussed previously. This allows the output to be displayed back to the terminal, as in the first example below, or out to another file, as in the second example.  
In this example, the file `select_example.sql` is located in the same directory as duckdb.exe and contains the following SQL statement:  
```sql
SELECT *
FROM generate_series(5);
```  
To execute it from the CLI, the `.read` command is used.  
```text
.read select_example.sql
```  
The output below is returned to the terminal by default. The formatting of the table can be adjusted using the `.output` or `.once` commands.  
```text
| generate_series |
|----------------:|
| 0               |
| 1               |
| 2               |
| 3               |
| 4               |
| 5               |
```  
Multiple commands, including both SQL and dot commands, can also be run in a single `.read` command. In this example, the file `write_markdown_to_file.sql` is located in the same directory as duckdb.exe and contains the following commands:  
```sql
.mode markdown
.output series.md
SELECT *
FROM generate_series(5);
```  
To execute it from the CLI, the `.read` command is used as before.  
```text
.read write_markdown_to_file.sql
```  
In this case, no output is returned to the terminal. Instead, the file `series.md` is created (or replaced if it already existed) with the markdown-formatted results shown here:  
```text
| generate_series |
|----------------:|
| 0               |
| 1               |
| 2               |
| 3               |
| 4               |
| 5               |
```  
<!-- The edit function does not appear to work -->