轻量级终端多数据库智能查询引擎
Lightweight Terminal Multi-Database Intelligent Query Engine
QueryPilot 是一款轻量级终端多数据库智能查询引擎,专为开发者打造。它提供了一个强大的交互式 REPL 环境,支持 SQLite、MySQL、PostgreSQL 等主流数据库,具备 SQL 语法高亮、智能自动补全、多种输出格式、连接管理、Schema 对比等核心功能。
在日常开发中,开发者经常需要在多种数据库客户端工具之间切换(如 DBeaver、Navicat、DataGrip),这些工具虽然功能强大,但往往体积庞大、启动缓慢、资源占用高。QueryPilot 的设计灵感来源于对轻量化、高效率、零门槛数据库查询工具的追求——一个打开即用、无需 GUI 的终端工具,特别适合 SSH 远程服务器环境。
- 🪶 极致轻量:仅依赖
prompt_toolkit一个外部包,SQLite 开箱即用 - 🎨 终端美化:SQL 语法高亮、动态表格对齐、ANSI 彩色输出
- 🧠 智能补全:自动补全 SQL 关键词、表名、列名
- 📊 多格式输出:表格 / JSON / CSV 一键切换
- 🔐 安全连接:命名连接管理,密码加密存储
- 🔄 Schema 对比:跨数据库结构差异分析,自动生成迁移 SQL
- ⚡ 批处理模式:支持 SQL 文件批量执行
| 特性 | 描述 |
|---|---|
| 🗄️ 多数据库支持 | SQLite(内置零依赖)、MySQL、PostgreSQL,适配器模式可扩展 |
| 💻 交互式 REPL | SQL 语法高亮、智能自动补全、命令历史、多行 SQL 支持 |
| 📄 批处理执行 | 通过 -f 参数执行 SQL 文件,支持管道输入 |
| 📊 多格式输出 | 表格(默认)、JSON、CSV,--format 参数切换 |
| 🔗 连接管理 | 保存/加载命名连接,密码 XOR+Base64 加密存储 |
| 🔄 Schema 对比 | 对比表结构、列定义、索引、外键,生成迁移 SQL |
| ⏱️ 查询统计 | 执行时间、影响行数等实时统计 |
| 🎨 彩色输出 | ANSI 彩色终端输出,--no-color 可关闭 |
- Python 3.9 或更高版本
- pip 包管理器
# 克隆仓库
git clone https://github.com/gitstq/QueryPilot.git
cd QueryPilot
# 安装(推荐使用虚拟环境)
python -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
pip install -e .# 启动交互式 REPL(默认使用内存 SQLite 数据库)
querypilot
# 连接 SQLite 数据库文件
querypilot -d mydb.sqlite
# 执行 SQL 文件
querypilot -f query.sql
# 以 JSON 格式输出
querypilot -f query.sql --format json
# 以 CSV 格式输出
querypilot -f query.sql --format csv# 安装数据库驱动(按需)
pip install pymysql # MySQL
pip install psycopg2-binary # PostgreSQL
# 保存 MySQL 连接
querypilot --save mydb -t mysql --host localhost --port 3306 -u root -p secret -d mydb
# 保存 PostgreSQL 连接
querypilot --save mypg -t postgres --host localhost --port 5432 -u postgres -p secret -d mydb
# 使用已保存的连接
querypilot -n mydb
querypilot -n mypg在 REPL 模式中,输入 SQL 语句后以分号 ; 结尾并回车即可执行。
| 命令 | 描述 |
|---|---|
\d |
列出所有表 |
\d <表名> |
查看表结构(列名、类型、是否可空等) |
\export <文件名> |
将上一次查询结果导出到文件 |
\format <格式> |
切换输出格式(table / json / csv) |
\h |
显示帮助信息 |
\q |
退出 REPL |
# 对比两个已保存连接的数据库结构
querypilot --diff source_conn target_conn
# 输出迁移 SQL
querypilot --diff source_conn target_conn --format sql# 通过管道传入 SQL
echo "SELECT 1 + 1 AS result;" | querypilot
# 结合其他工具
cat data.sql | querypilot -d mydb.sqlite --format jsonQueryPilot 遵循 "简单即力量" 的设计哲学:
- 零配置启动:无需安装 GUI,无需复杂配置,
pip install即可使用 - 渐进式复杂度:基础功能零学习成本,高级功能按需发现
- 适配器模式:统一的数据库接口抽象,新增数据库类型只需实现适配器
| 组件 | 选择 | 原因 |
|---|---|---|
| 语言 | Python 3.9+ | 生态丰富、开发效率高、跨平台 |
| REPL 框架 | prompt_toolkit | 成熟的终端交互库,支持补全和高亮 |
| 数据库抽象 | 适配器模式 | 松耦合、易扩展、统一接口 |
| 密码加密 | XOR + Base64 | 零外部依赖,满足基本安全需求 |
- 🔄 支持 Redis、MongoDB 等非关系型数据库
- 📊 查询结果可视化(柱状图、饼图)
- 🔔 查询性能分析与慢查询检测
- 📋 SQL 查询历史管理与搜索
- 🌐 ER 图自动生成
- 📦 打包为独立可执行文件(PyInstaller)
git clone https://github.com/gitstq/QueryPilot.git
cd QueryPilot
pip install -e .pip install querypilot| 环境 | 支持状态 |
|---|---|
| Linux (Ubuntu/Debian/CentOS) | ✅ 完全支持 |
| macOS (Intel / Apple Silicon) | ✅ 完全支持 |
| Windows (10/11) | ✅ 完全支持 |
| Python 3.9+ | ✅ 完全支持 |
欢迎社区贡献!请遵循以下规范:
- Fork 本仓库
- 创建特性分支:
git checkout -b feature/your-feature - 提交更改:
git commit -m "feat: 描述你的更改" - 推送分支:
git push origin feature/your-feature - 提交 Pull Request
遵循 Angular 提交规范:
feat:新增功能fix:修复问题docs:文档更新refactor:代码重构test:测试相关chore:构建/工具链相关
请使用 GitHub Issues 提交 Bug 报告或功能建议,并附上:
- 问题描述 / 复现步骤
- 运行环境(OS、Python 版本、数据库类型)
- 期望行为 vs 实际行为
本项目基于 MIT License 开源。
QueryPilot 是一款輕量級終端多資料庫智慧查詢引擎,專為開發者打造。它提供了一個強大的互動式 REPL 環境,支援 SQLite、MySQL、PostgreSQL 等主流資料庫,具備 SQL 語法高亮、智慧自動補全、多種輸出格式、連線管理、Schema 比對等核心功能。
在日常開發中,開發者經常需要在多種資料庫客戶端工具之間切換(如 DBeaver、Navicat、DataGrip),這些工具雖然功能強大,但往往體積龐大、啟動緩慢、資源佔用高。QueryPilot 的設計靈感來源於對輕量化、高效率、零門檻資料庫查詢工具的追求——一個開啟即用、無需 GUI 的終端工具,特別適合 SSH 遠端伺服器環境。
- 🪶 極致輕量:僅依賴
prompt_toolkit一個外部套件,SQLite 開箱即用 - 🎨 終端美化:SQL 語法高亮、動態表格對齊、ANSI 彩色輸出
- 🧠 智慧補全:自動補全 SQL 關鍵詞、表名、欄位名
- 📊 多格式輸出:表格 / JSON / CSV 一鍵切換
- 🔐 安全連線:命名連線管理,密碼加密儲存
- 🔄 Schema 比對:跨資料庫結構差異分析,自動生成遷移 SQL
- ⚡ 批次處理模式:支援 SQL 檔案批次執行
| 特性 | 描述 |
|---|---|
| 🗄️ 多資料庫支援 | SQLite(內建零依賴)、MySQL、PostgreSQL,介面卡模式可擴展 |
| 💻 互動式 REPL | SQL 語法高亮、智慧自動補全、命令歷史、多行 SQL 支援 |
| 📄 批次處理執行 | 透過 -f 參數執行 SQL 檔案,支援管道輸入 |
| 📊 多格式輸出 | 表格(預設)、JSON、CSV,--format 參數切換 |
| 🔗 連線管理 | 儲存/載入命名連線,密碼 XOR+Base64 加密儲存 |
| 🔄 Schema 比對 | 比對表結構、欄位定義、索引、外鍵,生成遷移 SQL |
| ⏱️ 查詢統計 | 執行時間、影響行數等即時統計 |
| 🎨 彩色輸出 | ANSI 彩色終端輸出,--no-color 可關閉 |
- Python 3.9 或更高版本
- pip 套件管理器
# 克隆倉庫
git clone https://github.com/gitstq/QueryPilot.git
cd QueryPilot
# 安裝(建議使用虛擬環境)
python -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
pip install -e .# 啟動互動式 REPL(預設使用記憶體 SQLite 資料庫)
querypilot
# 連線 SQLite 資料庫檔案
querypilot -d mydb.sqlite
# 執行 SQL 檔案
querypilot -f query.sql
# 以 JSON 格式輸出
querypilot -f query.sql --format json
# 以 CSV 格式輸出
querypilot -f query.sql --format csv# 安裝資料庫驅動(按需)
pip install pymysql # MySQL
pip install psycopg2-binary # PostgreSQL
# 儲存 MySQL 連線
querypilot --save mydb -t mysql --host localhost --port 3306 -u root -p secret -d mydb
# 儲存 PostgreSQL 連線
querypilot --save mypg -t postgres --host localhost --port 5432 -u postgres -p secret -d mydb
# 使用已儲存的連線
querypilot -n mydb
querypilot -n mypg在 REPL 模式中,輸入 SQL 語句後以分號 ; 結尾並按 Enter 即可執行。
| 命令 | 描述 |
|---|---|
\d |
列出所有表 |
\d <表名> |
查看表結構(欄位名、類型、是否可空等) |
\export <檔案名> |
將上一次查詢結果匯出到檔案 |
\format <格式> |
切換輸出格式(table / json / csv) |
\h |
顯示幫助資訊 |
\q |
退出 REPL |
# 比對兩個已儲存連線的資料庫結構
querypilot --diff source_conn target_conn
# 輸出遷移 SQL
querypilot --diff source_conn target_conn --format sql# 透過管道傳入 SQL
echo "SELECT 1 + 1 AS result;" | querypilot
# 結合其他工具
cat data.sql | querypilot -d mydb.sqlite --format jsonQueryPilot 遵循 「簡單即力量」 的設計哲學:
- 零配置啟動:無需安裝 GUI,無需複雜配置,
pip install即可使用 - 漸進式複雜度:基礎功能零學習成本,進階功能按需發現
- 介面卡模式:統一的資料庫介面抽象,新增資料庫類型只需實作介面卡
| 元件 | 選擇 | 原因 |
|---|---|---|
| 語言 | Python 3.9+ | 生態豐富、開發效率高、跨平台 |
| REPL 框架 | prompt_toolkit | 成熟的終端互動庫,支援補全和高亮 |
| 資料庫抽象 | 介面卡模式 | 鬆耦合、易擴展、統一介面 |
| 密碼加密 | XOR + Base64 | 零外部依賴,滿足基本安全需求 |
- 🔄 支援 Redis、MongoDB 等非關聯式資料庫
- 📊 查詢結果視覺化(柱狀圖、圓餅圖)
- 🔔 查詢效能分析與慢查詢偵測
- 📋 SQL 查詢歷史管理與搜尋
- 🌐 ER 圖自動生成
- 📦 打包為獨立可執行檔(PyInstaller)
git clone https://github.com/gitstq/QueryPilot.git
cd QueryPilot
pip install -e .| 環境 | 支援狀態 |
|---|---|
| Linux (Ubuntu/Debian/CentOS) | ✅ 完全支援 |
| macOS (Intel / Apple Silicon) | ✅ 完全支援 |
| Windows (10/11) | ✅ 完全支援 |
| Python 3.9+ | ✅ 完全支援 |
歡迎社群貢獻!請遵循以下規範:
- Fork 本倉庫
- 建立特性分支:
git checkout -b feature/your-feature - 提交變更:
git commit -m "feat: 描述你的變更" - 推送分支:
git push origin feature/your-feature - 提交 Pull Request
遵循 Angular 提交規範:
feat:新增功能fix:修復問題docs:文件更新refactor:程式碼重構test:測試相關chore:建構/工具鏈相關
本專案基於 MIT License 開源。
QueryPilot is a lightweight terminal multi-database intelligent query engine built for developers. It provides a powerful interactive REPL environment supporting SQLite, MySQL, and PostgreSQL, with features including SQL syntax highlighting, intelligent auto-completion, multiple output formats, connection management, and schema comparison.
In daily development, developers frequently switch between multiple database client tools (DBeaver, Navicat, DataGrip). While powerful, these tools are often bulky, slow to start, and resource-heavy. QueryPilot was inspired by the pursuit of a lightweight, efficient, zero-barrier database query tool — one that works out of the box in the terminal, with no GUI required, perfectly suited for SSH remote server environments.
- 🪶 Ultra Lightweight: Only one external dependency (
prompt_toolkit), SQLite works out of the box - 🎨 Beautiful Terminal: SQL syntax highlighting, dynamic table alignment, ANSI colored output
- 🧠 Smart Completion: Auto-complete SQL keywords, table names, and column names
- 📊 Multi-Format Output: Switch between Table / JSON / CSV with one flag
- 🔐 Secure Connections: Named connection management with encrypted password storage
- 🔄 Schema Diff: Cross-database structure comparison with migration SQL generation
- ⚡ Batch Mode: Execute SQL files in batch
| Feature | Description |
|---|---|
| 🗄️ Multi-Database Support | SQLite (built-in, zero deps), MySQL, PostgreSQL via adapter pattern |
| 💻 Interactive REPL | SQL syntax highlighting, smart auto-completion, command history, multi-line SQL |
| 📄 Batch Execution | Execute SQL files via -f flag, supports pipe input |
| 📊 Multi-Format Output | Table (default), JSON, CSV — switch with --format |
| 🔗 Connection Management | Save/load named connections with XOR+Base64 encrypted passwords |
| 🔄 Schema Comparison | Compare tables, columns, indexes, foreign keys; generate migration SQL |
| ⏱️ Query Statistics | Real-time execution time, rows affected |
| 🎨 Colored Output | ANSI colored terminal output, disable with --no-color |
- Python 3.9 or higher
- pip package manager
# Clone the repository
git clone https://github.com/gitstq/QueryPilot.git
cd QueryPilot
# Install (virtual environment recommended)
python -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
pip install -e .# Start interactive REPL (in-memory SQLite by default)
querypilot
# Connect to a SQLite database file
querypilot -d mydb.sqlite
# Execute a SQL file
querypilot -f query.sql
# Output as JSON
querypilot -f query.sql --format json
# Output as CSV
querypilot -f query.sql --format csv# Install database drivers (as needed)
pip install pymysql # MySQL
pip install psycopg2-binary # PostgreSQL
# Save a MySQL connection
querypilot --save mydb -t mysql --host localhost --port 3306 -u root -p secret -d mydb
# Save a PostgreSQL connection
querypilot --save mypg -t postgres --host localhost --port 5432 -u postgres -p secret -d mydb
# Use a saved connection
querypilot -n mydb
querypilot -n mypgIn REPL mode, enter SQL statements ending with a semicolon ; and press Enter to execute.
| Command | Description |
|---|---|
\d |
List all tables |
\d <table> |
Describe table structure (column names, types, nullable, etc.) |
\export <file> |
Export last query result to a file |
\format <fmt> |
Change output format (table / json / csv) |
\h |
Show help |
\q |
Quit REPL |
# Compare schemas between two saved connections
querypilot --diff source_conn target_conn
# Output migration SQL
querypilot --diff source_conn target_conn --format sql# Pipe SQL via stdin
echo "SELECT 1 + 1 AS result;" | querypilot
# Combine with other tools
cat data.sql | querypilot -d mydb.sqlite --format jsonQueryPilot follows the philosophy of "Simplicity is Power":
- Zero-config startup: No GUI needed, no complex setup —
pip installand go - Progressive complexity: Basic features have zero learning curve; advanced features are discovered on demand
- Adapter pattern: Unified database interface abstraction — adding a new database type only requires implementing an adapter
| Component | Choice | Rationale |
|---|---|---|
| Language | Python 3.9+ | Rich ecosystem, high development efficiency, cross-platform |
| REPL Framework | prompt_toolkit | Mature terminal interaction library with completion and highlighting |
| DB Abstraction | Adapter Pattern | Loose coupling, easy extension, unified interface |
| Password Encryption | XOR + Base64 | Zero external dependencies, meets basic security needs |
- 🔄 Support for Redis, MongoDB and other NoSQL databases
- 📊 Query result visualization (bar charts, pie charts)
- 🔔 Query performance analysis and slow query detection
- 📋 SQL query history management and search
- 🌐 Auto-generated ER diagrams
- 📦 Package as standalone executable (PyInstaller)
git clone https://github.com/gitstq/QueryPilot.git
cd QueryPilot
pip install -e .| Environment | Support Status |
|---|---|
| Linux (Ubuntu/Debian/CentOS) | ✅ Fully Supported |
| macOS (Intel / Apple Silicon) | ✅ Fully Supported |
| Windows (10/11) | ✅ Fully Supported |
| Python 3.9+ | ✅ Fully Supported |
Community contributions are welcome! Please follow these guidelines:
- Fork this repository
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -m "feat: describe your changes" - Push the branch:
git push origin feature/your-feature - Submit a Pull Request
Follow the Angular commit convention:
feat:New featurefix:Bug fixdocs:Documentation updaterefactor:Code refactoringtest:Test relatedchore:Build/toolchain related
Please use GitHub Issues to submit bug reports or feature requests, including:
- Problem description / reproduction steps
- Runtime environment (OS, Python version, database type)
- Expected behavior vs actual behavior
This project is licensed under the MIT License.
Made with ❤️ by gitstq