dbcls is a versatile client that supports various databases
Project description
DbCls
DbCls is a powerful database client that combines the functionality of a SQL editor and data visualization tool. It integrates the kaa editor for SQL query editing and the visidata tool for data representation, providing a seamless experience for database management and data analysis.
Features
- SQL query editing with syntax highlighting
- Direct query execution from the editor
- Data visualization with interactive tables
- Support for multiple database engines (MySQL, PostgreSQL, ClickHouse)
- Configuration via command line or config file
- Table schema inspection
- Database and table browsing
- Query history and file-based query storage
Screenshots
SQL Editor
Data Visualization
Installation
pip install dbcls
Quick Start
Basic usage with command line arguments:
dbcls -H 127.0.0.1 -u user -p mypasswd -E mysql -d mydb mydb.sql
Command Line Options
| Option | Description |
|---|---|
-H, --host |
Database host address |
-u, --user |
Database username |
-p, --password |
Database password |
-E, --engine |
Database engine (mysql, postgresql, clickhouse) |
-d, --database |
Database name |
-P, --port |
Port number (optional) |
-c, --config |
Path to configuration file |
--no-compress |
Disable compression for ClickHouse connections |
Configuration
Using a Config File
You can use a JSON configuration file instead of command line arguments:
dbcls -c config.json mydb.sql
Example config.json:
{
"host": "127.0.0.1",
"port": "3306",
"username": "user",
"password": "mypasswd",
"dbname": "mydb",
"engine": "mysql"
}
Using Bash Configuration
You can also provide configuration directly from a bash script:
#!/bin/bash
CONFIG='{
"host": "127.0.0.1",
"port": "3306",
"username": "user",
"password": "mypasswd",
"dbname": "mydb",
"engine": "mysql"
}'
dbcls -c <(echo "$CONFIG") mydb.sql
Editor Commands (kaaedit)
Hotkeys
| Hotkey | Action |
|---|---|
Alt + 1 |
Show autocompletion suggestions |
Alt + r |
Execute query under cursor or selected text |
Alt + e |
Show database list with table submenu |
Alt + t |
Show tables list with schema and sample data options |
Ctrl + q |
Quit application |
Ctrl + s |
Save file |
For more kaaedit hotkeys, visit: https://github.com/kaaedit/kaa
Navigation in Database and Table Listings
When using Alt + e (database list) or Alt + t (table list), you can navigate through the listings
Database List Navigation:
- Select a database and press
Enterto proceed to the table list for that database
Table List Navigation:
- Select a table and press
Enterto access options:- View table schema
- Show sample data
Data Visualization (visidata)
Hotkeys
| Hotkey | Action |
|---|---|
zf |
Format current cell (JSON indentation, number prettification) |
g+ |
Expand array vertically, similarly to how it's done in expand-col, but by creating new rows rather than columns |
E |
Edit the SQL query used to fetch sample data for the current table(in Alt + t page only) |
Exporting Data
DbCls supports exporting data from visidata in multiple formats:
SQL INSERT Export:
- After executing a query and viewing results in visidata, press either
Ctrl+Sto save orgYto copy to the clipboard - Enter filename with
.sqlextension (e.g.,output.sql) - The data will be saved as SQL INSERT statements
The SQL export uses the sheet name as the table name and includes all visible columns. Each row is exported as a separate INSERT statement.
For more visidata hotkeys, visit: https://www.visidata.org/man/
SQL Commands
| Command | Description |
|---|---|
.tables |
List all tables in current database |
.databases |
List all available databases |
.use <database> |
Switch to specified database |
.schema <table> |
Display schema for specified table |
Supported Database Engines
- MySQL
- PostgreSQL
- ClickHouse
- SQLite
Password safety
To ensure password safety, I recommend using the project ssh-crypt to encrypt your config file. This way, you can store your password securely and use it with dbcls.
Caveats:
- If you keep the raw password in a shell script, it will be visible to other users on the system.
- Even if you encrypt your password inside a shell script, if you pass it to dbcls via the command line, it will be visible in the process list.
To avoid this, you can use this technique:
#!/bin/bash
ENC_PASS='{V|B;*R$Ep:HtO~*;QAd?yR#b?V9~a34?!!sxqQT%{!x)bNby^5'
PASS_DEC=`ssh-crypt -d -s $PASS`
CONFIG=`cat << EOF
{
"host": "127.0.0.1",
"username": "user",
"password": "$PASS_DEC",
"dbname": "mydb",
"engine": "mysql"
}
`
dbcls -c <(echo "$CONFIG") mydb.sql
Contributing
Contributions are welcome! Please feel free to submit a Pull Request or submit an issue on GitHub Issues
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbcls-1.1.24.tar.gz.
File metadata
- Download URL: dbcls-1.1.24.tar.gz
- Upload date:
- Size: 33.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bfbaf5e6f7f704d408a1c544f998d65211fcf5f8b0a5f94608c7f3618dab5e2
|
|
| MD5 |
8d3aee7a6dd4d43bdf4f799345fd619f
|
|
| BLAKE2b-256 |
91b58b6d5aef5e0547308530c96362bc92e6d9e87dff2476575f38d4765c3690
|
File details
Details for the file dbcls-1.1.24-py3-none-any.whl.
File metadata
- Download URL: dbcls-1.1.24-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7e4a20ea6013f9c43a1a053fdcc52fb5d4b2b9602af99915b921cba6dfd7e73
|
|
| MD5 |
aaf613ff6ef492fb11a17468e8502efe
|
|
| BLAKE2b-256 |
44c8dd5d0eebc799461e7cfaa49ec01cec46869fa5c0befce36963541fbc3300
|