EdgeSQL Shell
Run a SQL Database from a terminal: every shell command and its arguments, the output modes, the import sources, and the credential variables.
EdgeSQL Shell is a Python command-line tool that manages SQL Database databases and runs SQL against them. It is not published on a package index: you clone the repository and install it from source. The shell authenticates with the AZION_TOKEN environment variable, and its prompt is EdgeSQL>. For the installation steps, refer to Install the EdgeSQL Shell.
Usage
Start EdgeSQL Shell from the directory you cloned it into, with its virtual environment active. Export the token first:
The shell opens on the EdgeSQL> prompt. Each line you enter is one command from the table under Commands, or a SQL statement that runs against the database in use.
Two flags run the shell without the prompt: -n makes the run non-interactive, and -c passes one command. Repeat -c to run several commands in order and exit:
Commands
EdgeSQL Shell accepts fifteen commands at the EdgeSQL> prompt. help with no argument prints the list of commands, and help .dump prints the text for one of them.
| Command | What it does |
|---|---|
help | Shows information about the available commands, or about one command. |
.databases | Lists all databases. |
.use <database-name> | Switches to a specific database. |
.tables | Lists all tables in the database. |
.schema <table-name> | Describes the schema of a specific table. |
.dbinfo | Retrieves information about the current database. |
.read <file_path> | Loads and runs the SQL statements held in a file. |
.create <database-name> | Creates a new database. |
.destroy <database-name> | Destroys a specific database. |
.output | Sets the output destination. |
.dump <table-name> | Renders the table structure as SQL. |
.mode | Sets the output mode. |
.import <params> <table-name> | Imports data from an external source into the table. |
.dbsize | Gets the size of the current database in MB. |
.exit | Exits the EdgeSQL Shell. |
.output
.output sets where EdgeSQL Shell writes results. Pass stdout to write them to the terminal:
Pass a file path to write them to that file instead:
.dump
.dump renders the structure of a table as SQL. It writes to the destination .output holds, so point .output at a file before you run it to save the dump to that file:
Two options narrow what it renders. --schema-only renders the schema of the table alone, and --data-only renders its data alone:
.mode
.mode sets the format EdgeSQL Shell prints results in. It takes one of seven values:
exceltabularcsvjsonhtmlmarkdownraw
Pass the value as the argument of the command:
.import
.import loads data from an external source into a table. Six sources are available. file and sqlite read from a path on your machine; kaggle, mysql, postgres, and turso reach a remote server and read their credentials from the variables under Environment variables. .import file accepts a CSV or an XLSX file and no other format.
| Source | Argument form |
|---|---|
file | .import file <csv|xlsx> <file_path> <table_name> |
kaggle | .import kaggle <dataset> <data_name> <table_name> |
mysql | .import mysql <database> <source_table> <table_name> |
postgres | .import postgres <database> <source_table> <table_name> |
sqlite | .import sqlite <file_path> <source_table> <table_name> |
turso | .import turso <database> <source_table> <table_name> |
help .import prints the parameters of every source. Select a database with .use first: with none selected, the command answers No database selected. Use '.use <database_name>' to select a database. instead of the help text.
The shell answers with this text:
That text does not match the shell it documents. It leaves sqlite out of the command formats, and it lists five formats against four examples, because postgres has no example. The turso example repeats the placeholders of its command format instead of showing a value. And Import data from file files is a typo the shell prints.
Environment variables
EdgeSQL Shell reads its credentials from the environment. Set each variable with export before you start the shell: the Azion personal token it authenticates with, and the credentials of the source an .import run reads from. The Required column states whether the source that reads a variable needs it.
| Source | Variable | Required | What it holds |
|---|---|---|---|
| Azion | AZION_TOKEN | Yes | The Azion personal token the shell authenticates with |
| Kaggle | KAGGLE_USERNAME | Yes | The Kaggle user name |
| Kaggle | KAGGLE_KEY | Yes | The Kaggle API key |
| MySQL | MYSQL_USERNAME | Yes | The user name on the MySQL server |
| MySQL | MYSQL_PASSWORD | Yes | The password of that user |
| MySQL | MYSQL_HOST | Yes | The address of the MySQL server |
| MySQL | MYSQL_PORT | No | The port of the MySQL server |
| MySQL | MYSQL_SSL_CA | No | The certificate authority for a TLS connection |
| MySQL | MYSQL_SSL_CERT | No | The client certificate for a TLS connection |
| MySQL | MYSQL_SSL_KEY | No | The client key for a TLS connection |
| MySQL | MYSQL_SSL_VERIFY_CERT | No | Whether the server certificate is verified: True or False |
| PostgreSQL | POSTGRES_USERNAME | Yes | The user name on the PostgreSQL server |
| PostgreSQL | POSTGRES_PASSWORD | Yes | The password of that user |
| PostgreSQL | POSTGRES_HOST | Yes | The address of the PostgreSQL server |
| PostgreSQL | POSTGRES_PORT | No | The port of the PostgreSQL server |
| PostgreSQL | POSTGRES_SSL_CA | No | The certificate authority for a TLS connection |
| PostgreSQL | POSTGRES_SSL_CERT | No | The client certificate for a TLS connection |
| PostgreSQL | POSTGRES_SSL_KEY | No | The client key for a TLS connection |
| PostgreSQL | POSTGRES_SSL_VERIFY_CERT | No | Whether the server certificate is verified: True or False |
| Turso | TURSO_DATABASE_URL | Yes | The database URL, shaped https://<db_name>-<organization>.turso.io |
| Turso | TURSO_AUTH_TOKEN | Yes | The Turso authentication token |
| Turso | TURSO_ENCRYPTION_KEY | No | The encryption key of the Turso database |
Set the token, and then the credentials of the source you import from:
Working commands
With the Kaggle import stubbed to get past the startup error, these commands work: .databases, .use, .tables, .schema, .dbinfo, .dbsize, .read, .import file csv, .import sqlite, .dump --schema-only, and a bare SELECT statement.
Four of them answer with a message or a table of their own. .read answers SQL statements from <file_path> executed successfully. and .import sqlite answers Data imported successfully into table '<table_name>'. .dbsize answers with a one-column table headed size_in_mb, and .dbinfo answers with an Attribute and Value table carrying Database ID, Database Name, Status, Active, Last Modified, Last Editor, and Product Version.
The argument forms of the other import sources, mysql, postgres, kaggle, and turso, come from the help .import text of the shell itself.