This guide walks you through cloning the repo, installing dependencies, running the test suite, and manually testing all features in the browser.
- Git
- Python 3.10+
- pip
- A running MySQL, PostgreSQL, or MSSQL instance for integration testing
git clone https://github.com/cloudpad9/db-viewer-python.git
cd db-viewer-pythonpython3 -m venv .venv
source .venv/bin/activate # macOS / Linux
# .venv\Scripts\activate # Windowspip install -e ".[dev]"This installs the package in editable mode along with all runtime and dev dependencies (fastapi, uvicorn, bcrypt, pymysql, psycopg2-binary, pymssql, openpyxl, httpx, pytest, pytest-asyncio).
Create a database connections file:
mkdir -p ~/.dbviewer/dataEdit ~/.dbviewer/data/connections.json:
[
{
"name": "Local MySQL",
"type": "mysql",
"server": "localhost",
"port": 3306,
"database": "test_db",
"user": "root",
"password": "yourpassword"
}
]Adjust the connection details to match your local database. You can add multiple connections for different database types.
pytest tests/ -vTo run a specific test file:
pytest tests/test_name_helper.py -v
pytest tests/test_auth.py -v
pytest tests/test_schema_diff.py -vdbviewer --no-auth --openThe --open flag opens the browser automatically. If it doesn't open, navigate to:
http://localhost:9876
dbviewerOpen http://localhost:9876 — a login dialog will appear. Use the default credentials:
Username: admin
Password: admin123
# Use a different port if 9876 is already taken
dbviewer --no-auth --port 8080 --open
# Run without opening the browser
dbviewer --no-auth
# See all available options
dbviewer --helpIf the dbviewer command is not found, run it directly with:
python -m dbviewer --no-auth --openWork through the following flows in order to verify all features.
- Select a connection from the Source dropdown
- The table list should populate with table names and row counts in parentheses
- Use the Search input above the table list to filter tables by name
- Select one or more tables in the list
- Click Concept — the response pane should show column names grouped by table
- Click Structure — should show column names + types, padded and formatted
- Click Describe — should show DESCRIBE output as HTML tables
- Click Indexes — should show index names and columns as preformatted text
- Select a table
- Click Data — the response pane should show a formatted HTML table with row numbers
- Enter
0,10in the limit input → click Data — should show first 10 rows - Click an editable cell (NAME, TITLE, etc.) — an inline editor should appear
- Change the value and press Enter or click away — the cell should update
- Type
SELECT * FROM your_table LIMIT 5in the query input - Click Execute — results should appear as an HTML table with elapsed time
- Click Explain — should show EXPLAIN output
- Click L (last row) — should show last 5 rows by ID
- Click LU (last update) — should show last 5 rows by LATEST_UPDATE
- Try a multi-query:
SELECT COUNT(*) FROM table1; SELECT COUNT(*) FROM table2— both results should appear
- Type
DELETE FROM test_tableand click Execute — should be blocked with "Query not allowed" - Type
DELETE FROM test_table//Confirmedand click Execute — should execute (use a test table!)
- Select a single table
- Click Snippets — should show a textarea with ALTER/SELECT/INSERT code templates
- Click Vue — should show generated Vue.js component code
- Click To string — should show table names in various formats
- Switch to the Operations tab
- Select a table → enter a new name → type
confirmedin confirmation → click Rename - Verify the table appears with the new name (click Refresh on the connection)
- Select the renamed table → enter original name → confirm → Rename back
- Test Clone: select a table, enter a name like
test_clone, confirm, click Clone - Test Truncate (dry-run): check dry-run, select the clone, click Truncate — should show SQL
- Test Drop (dry-run): check dry-run, click Drop — should show SQL
- Select a table in the Operations tab
- Enter a column name in the Column input (autocomplete should work)
- Click Search — should show tables containing that column
- Enter new name/type → check dry-run → click Alter — should show ALTER SQL
- Test Insert after (dry-run): enter an existing column, new column name + type
- Test Drop column (dry-run)
- Select a table
- Set operation to
SELECT * FROM, click Execute — should show results - Set operation to
UPDATE, choose SET column/value, WHERE column/value, click Execute
- Switch to the Databases tab
- Select a target connection from the dropdown
- Select some tables → click Diff — should show ALTER TABLE statements for differences
- Test Copy tables (dry-run): check dry-run, enter
copy Nconfirmation - Test Clone database (dry-run): check dry-run, enter
confirmed
- Switch to the Exporter tab
- Enter a SQL query:
SELECT * FROM your_table LIMIT 20 - Leave other fields empty → click Export
- An
.xlsxfile should download - Open it — should have formatted columns with row numbers
- Test with column titles, decimal columns, and sheet separation column
- Switch to the Importer tab
- Enter a path to a
.sqlfile on the server - Click Import (use a test file!)
- Ensure AI API key is configured in
~/.dbviewer/data/config.json - Select tables → type a question in the AI chat input (Viewer tab)
- Click Send — should show the AI's query + results
- Switch to AI Generator tab → check dry-run → click Generate Compact Form Layout — should show the prompt
To change the admin password interactively:
dbviewer --change-passwordFollow the prompts in the terminal. After changing, restart the server and verify login works with the new password.
It is recommended to test this on a clean machine or VM to avoid affecting your current environment.
# Check bash syntax without executing
bash -n install.sh
# Run the installer — creates ~/.dbviewer/
bash install.shAfter installation, open a new terminal and run:
dbviewer --no-auth --openTo uninstall:
rm -rf ~/.dbviewer
# Remove the PATH line from ~/.bashrc and/or ~/.zshrc| Symptom | Likely cause | Fix |
|---|---|---|
ModuleNotFoundError: pymysql |
Dependencies not installed | Run pip install -e ".[dev]" |
Address already in use on port 9876 |
Another process is using the port | Run lsof -i :9876 and kill the PID, or use --port 8080 |
| Login dialog persists after correct credentials | API call is failing | Open DevTools (F12) → Network tab → inspect the /api/login response |
| Table list is empty after selecting connection | Database connection failed | Check connection settings in connections.json; verify the database is reachable |
dbviewer: command not found |
Entry point not on PATH | Use python -m dbviewer --no-auth instead |
| Query returns no results | Table is empty or query is wrong | Try SELECT COUNT(*) FROM table to verify |
| Excel export fails | Missing openpyxl |
Run pip install openpyxl |
| AI features not working | API key not configured | Add API key to ~/.dbviewer/data/config.json |
| Column autocomplete not appearing | Column names not loaded | Click on a different connection and back, or reload the page |
| Inline cell editing not saving | UPDATE query failing | Check DevTools console for errors; verify the table has a UUID column |