Skip to content

Commit

Permalink
[EDU-5660] EdgeSQL Shell commands reference (#1373)
Browse files Browse the repository at this point in the history
* feat: add install sql shell guide

* feat: translate install sql shell guide to pt-br

* feat: add edge sql shell commands reference

* feat: translation of reference to pt-br

* feat: minor chnges

* fix: minor adjustmentes

* refactor: exlcude files

* fix link

* Apply suggestions from code review

Co-authored-by: isidrohernandezazion <isidro.hernandez@azion.com>

---------

Co-authored-by: isidrohernandezazion <isidro.hernandez@azion.com>
  • Loading branch information
guiafonso-ol and isidrohernandezazion authored Nov 21, 2024
1 parent a810b89 commit 58e333a
Show file tree
Hide file tree
Showing 3 changed files with 555 additions and 1 deletion.
277 changes: 277 additions & 0 deletions src/content/docs/en/pages/store-journey/sql/edgesql-shell-commands.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
---
title: How to use EdgeSQL Shell commands
description: >-
Learn how to use EdgeSQL Shell commands to interact with your Edge SQL database.
permalink: /documentation/products/store/sql/edge-sql-shell-commands/
meta_tags: >-
EdgeSQL, SQL commands, database management, command-line interface
namespace: docs_store_journey_sql_edge_sql_shell_commands
menu_namespace: storeMenu
---

import LinkButton from 'azion-webkit/linkbutton'

EdgeSQL Shell provides a command-line interface to manage and interact with your Edge SQL databases. Beyond executing SQL queries, it offers a comprehensive set of commands for database administration and configuration.

This guide covers the available commands for interacting with the EdgeSQL service and managing environment variables.

## EdgeSQL Shell commands

### help

Shows information about the available commands or a specific command.

```sh
EdgeSQL> help
```

Example:

```sh
EdgeSQL> help .dump
```

### .databases

Lists all databases.

```sh
EdgeSQL> .databases
```

### .use

Switches to a specific database.

```sh
EdgeSQL> .use <database-name>
```

### .tables

Lists all tables in the database.

```sh
EdgeSQL> .tables
```

### .schema

Describes the schema of a specific table.

```sh
EdgeSQL> .schema <table-name>
```

### .dbinfo

Retrieves information about the current database.

```sh
EdgeSQL> .dbinfo
```

### .read

Loads and executes SQL queries from a file.

```sh
EdgeSQL> .read <file_path>
```

### .create

Creates a new database.

```sh
EdgeSQL> .create <database-name>
```

### .destroy

Destroys a specific database.

```sh
EdgeSQL> .destroy <database-name>
```

### .output

Sets the output destination. Pass `stdout` as parameter to output to the console or inform a **file path** to define it as the output destination.

```sh
EdgeSQL> .output stdout
```

Example using a file as destination:

```sh
EdgeSQL> .output /file.csv
```

### .dump

Renders the table structure as SQL. After running the `output` command and setting the output to a file, the `dump` command will save the output to the selected file.

```sh
EdgeSQL> .dump <table-name>
```

You can pass the options `--schema-only` or `--data-only` to optionally render only the schema or the data of the table.

Example:

```sh
EdgeSQL> .dump --schema-only <table-name>
```

### .mode

Sets the output mode. You can choose one of the following options:

- excel
- tabular
- csv
- json
- html
- markdown
- raw

Example:

```sh
EdgeSQL> .mode tabular
```

### .import

Imports data from an external source into the table. You can import data from a file or from a MySQL, Postgres, Kaggle or Turso database.

```sh
EdgeSQL> .import <params> <table-name>
```

By running the `help` command you can get a list of the possible parameters for importing data:

```sh
EdgeSQL> help .import
```

You will receive a response similar to this:

```sh
.import: Import data from file files, Kaggle datasets, or databases into a database table.

Args:
arg (str): The import command and its arguments.

Command Formats:
.import file <csv|xlsx> <file_path> <table_name>: Import data from a file CSV or Excel file.
.import kaggle <dataset> <data_name> <table_name>: Import data from a Kaggle dataset.
.import mysql <database> <source_table> <table_name>: Import data from a MySQL database table.
.import postgres <database> <source_table> <table_name>: Import data from PostgreSQL database table.
.import turso <database> <source_table> <table_name>: Import data from Turso database.

Examples:
.import file csv /path/to/file.csv my_table
.import kaggle joonasyoon/google-doodles list.csv list
.import mysql mydb_name source_table_name my_table
.import turso <database> <source_table> <table_name>
```

### .dbsize

Gets the size of the current database in MB.

```sh
EdgeSQL> .dbsize
```

### .exit

Exits the EdgeSQL Shell.

```sh
EdgeSQL> .exit
```

## Environment variables

When using the EdgeSQL Shell to import data from external sources, you can send the credentials and tokens as environment variables byt using the `export` command. This command is also used for setting your Azion **personal token**.

### Personal token

You can send your **personal token** as an environment variable in EdgeSQL Shell.

```sh
export AZION_TOKEN="<your_auth_token_here>"
```

### Kaggle credentials

Use the following commands to set your Kaggle credentials:

```sh
export KAGGLE_USERNAME="<username>"
export KAGGLE_KEY="<kaggle_api_key>"
```

### MySQL credentials

Use the following commands to set your MySQL credentials:

```sh
export MYSQL_USERNAME="<username>"
export MYSQL_PASSWORD="<password>"
export MYSQL_HOST="<host_address>"
```

Optional settings for MySQL:

```sh
export MYSQL_PORT=<port>

# For TLS connection
export MYSQL_SSL_CA="<ssl_ca>"
export MYSQL_SSL_CERT="<ssl_cert>"
export MYSQL_SSL_KEY="<ssl_key>"
export MYSQL_SSL_VERIFY_CERT=<True|False>
```

### PostgreSQL credentials

Use the following commands to set your PostgreSQL credentials:

```sh
export POSTGRES_USERNAME="<username>"
export POSTGRES_PASSWORD="<password>"
export POSTGRES_HOST="<host_address>"
```

Optional settings for PostgreSQL:

```sh
export POSTGRES_PORT=<port>

# For TLS connection
export POSTGRES_SSL_CA="<ssl_ca>"
export POSTGRES_SSL_CERT="<ssl_cert>"
export POSTGRES_SSL_KEY="<ssl_key>"
export POSTGRES_SSL_VERIFY_CERT=<True|False>
```

### Turso credentials

Use the following commands to set your Turso credentials:

```sh
export TURSO_DATABASE_URL=<https://<db_name>-<organization>.turso.io
export TURSO_AUTH_TOKEN=<token>
```

Optional settings for Turso:
```sh
export TURSO_ENCRYPTION_KEY=<encryption_key>
```

<LinkButton link="/en/documentation/products/store/sql/install-edge-sql-shell" label="Go to EdgeSQL Shell installation guide" severity="secondary" />
Loading

0 comments on commit 58e333a

Please sign in to comment.