Skip to content

API Reference

A command line interface (CLI) for interacting with SQLModel.

Usage:

$ sqlcli [OPTIONS] COMMAND [ARGS]...

Options:

  • --version: Show the installed version. [default: False]
  • --install-completion [bash|zsh|fish|powershell|pwsh]: Install completion for the specified shell.
  • --show-completion [bash|zsh|fish|powershell|pwsh]: Show completion for the specified shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Commands:

  • create-all: Create a database.
  • docs: Opens the docs.
  • drop-all: Drop a database.
  • init-demo: Create a demo database for exploring sqlcli.
  • insert: Insert a new record into the database.
  • inspect: Inspect a SQLModel with rich.inspect.
  • select: Query the database.

sqlcli create-all

Create a database. The equivalent to calling SQLModel.metadata.create_all(engine).

Usage:

$ sqlcli create-all [OPTIONS]

Options:

  • -d, --database-url TEXT: A database connection string. If no connection string is provided sqlcli willcheck for a connection string in the environment variable DATABASE_URL.
  • -m, --models-path TEXT: The location of the python script(s) that contain the SQLModels. If no argumentis provided sqlcli will check for a path in the environment variableMODELS_PATH.
  • --help: Show this message and exit.

sqlcli docs

Opens the docs.

Open the docs using you default browser https://samedwardes.github.io/sqlcli/.

Usage:

$ sqlcli docs [OPTIONS]

Options:

  • --help: Show this message and exit.

sqlcli drop-all

Drop a database. The equivalent to calling SQLModel.metadata.drop_all(engine).

Usage:

$ sqlcli drop-all [OPTIONS]

Options:

  • -d, --database-url TEXT: A database connection string. If no connection string is provided sqlcli willcheck for a connection string in the environment variable DATABASE_URL.
  • -m, --models-path TEXT: The location of the python script(s) that contain the SQLModels. If no argumentis provided sqlcli will check for a path in the environment variableMODELS_PATH.
  • -y: Danger! Skip the prompt and drop the database. This cannot be undone. [default: False]
  • --help: Show this message and exit.

sqlcli init-demo

Create a demo database for exploring sqlcli.

Create a demo sqlite database to test with sqlcli. Calling this command will create two new files:

  1. ./sqlcli_demo/database.db: a sqlite data populated with a small amount of data.
  2. ./sqlcli_demo/models.py: a python module with SQLModel classes.

These files can used to test sqlcli without connecting to your own database. Once you are done with the demo files they can be deleted by calling sqlcli init-demo --clear.

Usage:

$ sqlcli init-demo [OPTIONS]

Options:

  • --path TEXT: The path to save the demo database. [default: sqlcli_demo]
  • --clear / --no-clear: Remove all of the demo database related data including sqlcli_demo/models.py and sqlcli_demo/database.db. [default: False]
  • --help: Show this message and exit.

sqlcli insert

Insert a new record into the database.

Insert new rows into the database. Calling sqlcli insert is similar to calling INSERT INTO [table] in sql.

Usage:

$ sqlcli insert [OPTIONS] [TABLE_NAME]

Arguments:

  • [TABLE_NAME]: The name of the table to query. If no name is provided the interactive promptwill ask for a table name.

Options:

  • -d, --database-url TEXT: A database connection string. If no connection string is provided sqlcli willcheck for a connection string in the environment variable DATABASE_URL.
  • -m, --models-path TEXT: The location of the python script(s) that contain the SQLModels. If no argumentis provided sqlcli will check for a path in the environment variableMODELS_PATH.
  • --help: Show this message and exit.

sqlcli inspect

Inspect a SQLModel with rich.inspect.

Usage:

$ sqlcli inspect [OPTIONS] [TABLE_NAME]

Arguments:

  • [TABLE_NAME]: The name of the table to query. If no name is provided the interactive promptwill ask for a table name.

Options:

  • -d, --database-url TEXT: A database connection string. If no connection string is provided sqlcli willcheck for a connection string in the environment variable DATABASE_URL.
  • -m, --models-path TEXT: The location of the python script(s) that contain the SQLModels. If no argumentis provided sqlcli will check for a path in the environment variableMODELS_PATH.
  • --help: Show this message and exit.

sqlcli select

Query the database.

Query the database to see the data inside a given table. Calling sqlcli select is similar to calling SELECT * FROM [table] in sql.

Usage:

$ sqlcli select [OPTIONS] [TABLE_NAME]

Arguments:

  • [TABLE_NAME]: The name of the table to query. If no name is provided the interactive promptwill ask for a table name.

Options:

  • -n, --number-rows INTEGER: The number of database rows to query. [default: 10]
  • -f, --format TEXT: The format to output the data. Should be one of ['table', 'json', 'dict']. [default: table]
  • -d, --database-url TEXT: A database connection string. If no connection string is provided sqlcli willcheck for a connection string in the environment variable DATABASE_URL.
  • -m, --models-path TEXT: The location of the python script(s) that contain the SQLModels. If no argumentis provided sqlcli will check for a path in the environment variableMODELS_PATH.
  • -v, --verbose: Show a more verbose output. [default: False]
  • --help: Show this message and exit.