Features
Demo
Create a demo database to explore test sqlcli by using the init-demo
command:
$ sqlcli init-demo
───────────────────────── table: sport ──────────────────────────
┏━━━━━━━━┳━━━━┓
┃ name ┃ id ┃
┡━━━━━━━━╇━━━━┩
│ Soccer │ 1 │
│ Hockey │ 2 │
└────────┴────┘
──────────────────────── table: athlete ─────────────────────────
┏━━━━┳━━━━━━━━━━┳━━━━━━━━━━┓
┃ id ┃ sport_id ┃ name ┃
┡━━━━╇━━━━━━━━━━╇━━━━━━━━━━┩
│ 1 │ 1 │ Ronaldo │
│ 2 │ 1 │ Messi │
│ 3 │ 1 │ Beckham │
│ 4 │ 2 │ Gretzky │
│ 5 │ 2 │ Crosby │
│ 6 │ 2 │ Ovechkin │
│ 7 │ 2 │ Sundin │
│ 8 │ 2 │ Domi │
└────┴──────────┴──────────┘
───────────────── how to use the demo database ──────────────────
A demo database has been created at:
/Users/samedwardes/git/sqlcli/sqlcli_demo/database.db
Demo models have been saved to:
/Users/samedwardes/git/sqlcli/sqlcli_demo/models.py
Here are some example commands to get you started:
sqlcli select athlete -d "sqlite:///sqlcli_demo/database.db" -m sqlcli_demo/models.py
sqlcli insert -d "sqlite:///sqlcli_demo/database.db" -m sqlcli_demo/models.py
To avoid passing in the `-d` and -`m` option everytime you can set the following environment
variables:
export DATABASE_URL="sqlite:///sqlcli_demo/database.db"
export MODELS_PATH="sqlcli_demo/models.py"
For instructions on how to use the demo database visit
https://samedwardes.github.io/sqlcli/tutorial/using-demo-db/.
Select
Select data from your SQL database using the select
command:
$ sqlcli select athlete -d "sqlite:///sqlcli_demo/database.db" -m "sqlcli_demo/models.py"
┏━━━━┳━━━━━━━━━━┳━━━━━━━━━━┓
┃ id ┃ sport_id ┃ name ┃
┡━━━━╇━━━━━━━━━━╇━━━━━━━━━━┩
│ 1 │ 1 │ Ronaldo │
│ 2 │ 1 │ Messi │
│ 3 │ 1 │ Beckham │
│ 4 │ 2 │ Gretzky │
│ 5 │ 2 │ Crosby │
│ 6 │ 2 │ Ovechkin │
│ 7 │ 2 │ Sundin │
│ 8 │ 2 │ Domi │
└────┴──────────┴──────────┘
Insert
Interactively insert new data using the insert
command:
$ sqlcli insert athlete -d "sqlite:///sqlcli_demo/database.db" -m "sqlcli_demo/models.py"
───────────────────────── column: `id` ──────────────────────────
# <class 'int'> (optional):$
──────────────────────── column: `name` ─────────────────────────
# <class 'str'>:$ Carter
────────────────────── column: `sport_id` ───────────────────────
The column `sport_id` is a foreign key related to the `sport` table. Please select from one of the
options below from the `id` column:
sport
┏━━━━━━━━┳━━━━┓
┃ name ┃ id ┃
┡━━━━━━━━╇━━━━┩
│ Soccer │ 1 │
│ Hockey │ 2 │
└────────┴────┘
# <class 'int'> (optional) [1/2]:$ 1
╭──────────────── New row successfully added 🎉 ────────────────╮
│ {'id': 9, 'sport_id': 1, 'name': 'Carter'} │
╰───────────────────────────────────────────────────────────────╯
Set defaults
Type less by setting a default database url and models module: