Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simatwa/sqlite3-cli-manager
Python tool designed to interact with SQLite databases via command-line interface
https://github.com/simatwa/sqlite3-cli-manager
database-manag database-manager sqlite sqlite-manager sqlite3 sqlite3-manager
Last synced: 3 days ago
JSON representation
Python tool designed to interact with SQLite databases via command-line interface
- Host: GitHub
- URL: https://github.com/simatwa/sqlite3-cli-manager
- Owner: Simatwa
- License: mit
- Created: 2024-11-07T08:50:44.000Z (11 days ago)
- Default Branch: main
- Last Pushed: 2024-11-07T15:38:46.000Z (10 days ago)
- Last Synced: 2024-11-07T15:43:17.694Z (10 days ago)
- Topics: database-manag, database-manager, sqlite, sqlite-manager, sqlite3, sqlite3-manager
- Language: Python
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
sqlite3-cli-manager
This tool is designed to interact with SQLite databases via command-line interface. Other than just issuing the sql staments by yourself, you can let AI generate sql statements based on your prompt.
# Pre-requisite
- [x] [Python>=3.12](https://python.org) *(optional)*
# Installation and Usage
## Installation
- Clone repo and install requirements
```sh
git clone https://github.com/Simatwa/sqlite3-cli-manager.git
cd sqlite3-cli-manager
pip install -r requirements.txt
```Alternatively, you can download standalone executables for your system from [here](https://github.com/Simatwa/sqlite3-cli-manager/releases/latest).
## Usage
$ python manager.py --help
```
Usage: manager.py [OPTIONS] COMMAND [ARGS]...Interact with SQLite databases via command-line interface
Options:
--version Show the version and exit.
--help Show this message and exit.Commands:
execute Run sql statements against database [AUTO-COMMITS]
interactive Execute sql statements interactively
show-columns List columns for a particular table
show-tables List tables contained in the database```
### Execute
- The `execute` command accepts multiple sql statements and run each against the database before auto-commiting the changes.
$ python manager.py execute --help
```
Usage: sqlite-manager execute [OPTIONS] DATABASERun sql statements against database [AUTO-COMMITS]
Options:
-s, --sql TEXT Sql statements [required]
-j, --json Stdout results in json format
-q, --quiet Do not stdout results
--help Show this message and exit.
````$ sqlite-manager execute -s ""`
> For example:
$ python manager execute test.db -s "select * from linux"
```
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Index ┃ Col. 1 ┃ Col. 2 ┃ Col. 3 ┃ Col. 4 ┃ Col. 5 ┃ Col. 6 ┃ Col. 7 ┃
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ 0 │ 1 │ Parrot │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
│ │ │ │ │ │ │ 13:22:13 │ 13:22:13 │
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
│ 1 │ 2 │ Kali │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
│ │ │ │ │ │ │ 13:22:21 │ 13:22:21 │
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
│ 2 │ 3 │ Ubuntu │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
│ │ │ │ │ │ │ 13:48:18 │ 13:48:18 │
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
│ 3 │ 4 │ Fedora │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
│ │ │ │ │ │ │ 13:48:49 │ 13:48:49 │
└───────┴────────┴────────┴───────────┴────────┴────────┴────────────┴────────────┘
```---
### Interactive
- The `interactive` command launches a recursive prompt that takes in sql statements and proceed to run them against the database.
$ python manager.py interactive --help
```
Usage: manager.py interactive [OPTIONS] DATABASEExecute sql statements interactively
Options:
-c, --color TEXT Results font color
-j, --json Stdout results in json format
-a, --auto-commit Enable auto-commit
-C, --disable-coloring Stdout prompt text in white font color
-S, --disable-suggestions Do not suggest sql statements
-N, --new-history-thread Start a new history thread
--help Show this message and exit.
````$ sqlite-manager execute -s ""`
> For example:
$ python manager.py interactive test.db
```
Welcome to interactive sqlite3-db manager.
Run help or h for usage info.
Repo : https://github.com/Simatwa/sqlite3-cli-manager
╰─>select * from Linux
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Index ┃ Col. 1 ┃ Col. 2 ┃ Col. 3 ┃ Col. 4 ┃ Col. 5 ┃ Col. 6 ┃ Col. 7 ┃
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ 0 │ 1 │ Parrot │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
│ │ │ │ │ │ │ 13:22:13 │ 13:22:13 │
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
│ 1 │ 2 │ Kali │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
│ │ │ │ │ │ │ 13:22:21 │ 13:22:21 │
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
│ 2 │ 3 │ Ubuntu │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
│ │ │ │ │ │ │ 13:48:18 │ 13:48:18 │
├───────┼────────┼────────┼───────────┼────────┼────────┼────────────┼────────────┤
│ 3 │ 4 │ Fedora │ community │ None │ 1 │ 2024-11-07 │ 2024-11-07 │
│ │ │ │ │ │ │ 13:48:49 │ 13:48:49 │
└───────┴────────┴────────┴───────────┴────────┴────────┴────────────┴────────────┘
╭─[Smartwa@localhost](smartBet2.db)~[🕒16:55:56-💻00:00:03-⚡-3.9s]
╰─>select * from
select * from Linux
select * from sqlite_schema
select * from sqlite_temp_schema```
---
### Show-columns
- The `show-columns` command lists the columns for a particular table in the database.
$ python manager.py show-columns --help
```
Usage: sqlite-manager show-columns [OPTIONS] DATABASE TABLEList columns for a particular table
Options:
-j, --json Stdout results in json format
--help Show this message and exit.
````$ python manager.py show-columns "`
> For example:
$ python manager.py show-columns test.db linux
```
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ Index ┃ Col. 1 ┃ Col. 2 ┃ Col. 3 ┃ Col. 4 ┃ Col. 5 ┃ Col. 6 ┃
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━┩
│ 0 │ 0 │ id │ INTEGER │ 0 │ None │ 1 │
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
│ 1 │ 1 │ distro │ TEXT │ 1 │ None │ 0 │
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
│ 2 │ 2 │ org │ TEXT │ 0 │ 'community' │ 0 │
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
│ 3 │ 3 │ logo │ BLOB NULLABLE │ 0 │ None │ 0 │
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
│ 4 │ 4 │ is_maintained │ BOOLEAN │ 0 │ 1 │ 0 │
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
│ 5 │ 5 │ updated_on │ TIMESTAMP │ 0 │ CURRENT_TIM… │ 0 │
├───────┼────────┼───────────────┼───────────────┼────────┼──────────────┼────────┤
│ 6 │ 6 │ created_at │ TIMESTAMP │ 1 │ CURRENT_TIM… │ 0 │
└───────┴────────┴───────────────┴───────────────┴────────┴──────────────┴────────┘
```---
### Show-tables
- The `show-tables` command lists the available tables across the entire database.
$ python manager.py show-tables --help
```
Usage: manager.py show-tables [OPTIONS] DATABASEList tables contained in the database
Options:
-j, --json Stdout results in json format
--help Show this message and exit.
````$ python manager.py show-tables `
> For example:
$ python manager.py show-tables test.db
```
┏━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┓
┃ Index ┃ Col. 1 ┃ Col. 2 ┃ Col. 3 ┃ Col. 4 ┃ Col. 5 ┃ Col. 6 ┃
┡━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━┩
│ 0 │ main │ sqlite_sequence │ table │ 2 │ 0 │ 0 │
├───────┼────────┼────────────────────┼────────┼────────┼────────┼────────┤
│ 1 │ main │ Linux │ table │ 7 │ 0 │ 0 │
├───────┼────────┼────────────────────┼────────┼────────┼────────┼────────┤
│ 2 │ main │ sqlite_schema │ table │ 5 │ 0 │ 0 │
├───────┼────────┼────────────────────┼────────┼────────┼────────┼────────┤
│ 3 │ temp │ sqlite_temp_schema │ table │ 5 │ 0 │ 0 │
└───────┴────────┴────────────────────┴────────┴────────┴────────┴────────┘
```# Contrubutions
Contributions are always welcoming. Consider implementing new feature or fixing my bad code.
## ToDo
1. [ ] Let AI generate sql statements based on user's prompt.