sql-assistant 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. sql_assistant-1.0.0/.gitignore +116 -0
  2. sql_assistant-1.0.0/LICENSE +21 -0
  3. sql_assistant-1.0.0/PKG-INFO +24 -0
  4. sql_assistant-1.0.0/README.md +447 -0
  5. sql_assistant-1.0.0/pyproject.toml +34 -0
  6. sql_assistant-1.0.0/src/sql_assistant/__init__.py +3 -0
  7. sql_assistant-1.0.0/src/sql_assistant/api/__init__.py +1 -0
  8. sql_assistant-1.0.0/src/sql_assistant/api/backup.py +116 -0
  9. sql_assistant-1.0.0/src/sql_assistant/api/config.py +183 -0
  10. sql_assistant-1.0.0/src/sql_assistant/api/conversation.py +71 -0
  11. sql_assistant-1.0.0/src/sql_assistant/api/dependencies.py +22 -0
  12. sql_assistant-1.0.0/src/sql_assistant/api/history.py +61 -0
  13. sql_assistant-1.0.0/src/sql_assistant/api/models.py +221 -0
  14. sql_assistant-1.0.0/src/sql_assistant/api/query.py +275 -0
  15. sql_assistant-1.0.0/src/sql_assistant/api/routes.py +19 -0
  16. sql_assistant-1.0.0/src/sql_assistant/api/schema.py +21 -0
  17. sql_assistant-1.0.0/src/sql_assistant/config.py +144 -0
  18. sql_assistant-1.0.0/src/sql_assistant/database/__init__.py +1 -0
  19. sql_assistant-1.0.0/src/sql_assistant/database/backup.py +568 -0
  20. sql_assistant-1.0.0/src/sql_assistant/database/connectors/__init__.py +1 -0
  21. sql_assistant-1.0.0/src/sql_assistant/database/connectors/base.py +185 -0
  22. sql_assistant-1.0.0/src/sql_assistant/database/connectors/exceptions.py +88 -0
  23. sql_assistant-1.0.0/src/sql_assistant/database/connectors/mongodb.py +194 -0
  24. sql_assistant-1.0.0/src/sql_assistant/database/connectors/mysql.py +110 -0
  25. sql_assistant-1.0.0/src/sql_assistant/database/connectors/postgresql.py +133 -0
  26. sql_assistant-1.0.0/src/sql_assistant/database/connectors/redis.py +132 -0
  27. sql_assistant-1.0.0/src/sql_assistant/database/connectors/sqlserver.py +140 -0
  28. sql_assistant-1.0.0/src/sql_assistant/database/history.py +290 -0
  29. sql_assistant-1.0.0/src/sql_assistant/database/manager.py +178 -0
  30. sql_assistant-1.0.0/src/sql_assistant/database/security.py +230 -0
  31. sql_assistant-1.0.0/src/sql_assistant/llm/__init__.py +1 -0
  32. sql_assistant-1.0.0/src/sql_assistant/llm/base.py +28 -0
  33. sql_assistant-1.0.0/src/sql_assistant/llm/exceptions.py +96 -0
  34. sql_assistant-1.0.0/src/sql_assistant/llm/manager.py +82 -0
  35. sql_assistant-1.0.0/src/sql_assistant/llm/prompts.py +29 -0
  36. sql_assistant-1.0.0/src/sql_assistant/llm/providers/__init__.py +1 -0
  37. sql_assistant-1.0.0/src/sql_assistant/llm/providers/claude.py +132 -0
  38. sql_assistant-1.0.0/src/sql_assistant/llm/providers/gemini.py +127 -0
  39. sql_assistant-1.0.0/src/sql_assistant/llm/providers/openai_compatible.py +103 -0
  40. sql_assistant-1.0.0/src/sql_assistant/llm/retry.py +88 -0
  41. sql_assistant-1.0.0/src/sql_assistant/main.py +94 -0
  42. sql_assistant-1.0.0/src/sql_assistant/settings.py +219 -0
  43. sql_assistant-1.0.0/src/sql_assistant/web/__init__.py +1 -0
  44. sql_assistant-1.0.0/src/sql_assistant/web/static/css/base.css +25 -0
  45. sql_assistant-1.0.0/src/sql_assistant/web/static/css/components/backup.css +146 -0
  46. sql_assistant-1.0.0/src/sql_assistant/web/static/css/components/chat.css +465 -0
  47. sql_assistant-1.0.0/src/sql_assistant/web/static/css/components/modal.css +143 -0
  48. sql_assistant-1.0.0/src/sql_assistant/web/static/css/components/settings.css +358 -0
  49. sql_assistant-1.0.0/src/sql_assistant/web/static/css/components/sidebar.css +235 -0
  50. sql_assistant-1.0.0/src/sql_assistant/web/static/css/components/toast.css +30 -0
  51. sql_assistant-1.0.0/src/sql_assistant/web/static/css/style.css +10 -0
  52. sql_assistant-1.0.0/src/sql_assistant/web/static/css/theme.css +200 -0
  53. sql_assistant-1.0.0/src/sql_assistant/web/static/js/api.js +38 -0
  54. sql_assistant-1.0.0/src/sql_assistant/web/static/js/app.js +161 -0
  55. sql_assistant-1.0.0/src/sql_assistant/web/static/js/backup.js +216 -0
  56. sql_assistant-1.0.0/src/sql_assistant/web/static/js/chat.js +238 -0
  57. sql_assistant-1.0.0/src/sql_assistant/web/static/js/color-theme-manager.js +121 -0
  58. sql_assistant-1.0.0/src/sql_assistant/web/static/js/confirm.js +95 -0
  59. sql_assistant-1.0.0/src/sql_assistant/web/static/js/conversations.js +182 -0
  60. sql_assistant-1.0.0/src/sql_assistant/web/static/js/settings.js +425 -0
  61. sql_assistant-1.0.0/src/sql_assistant/web/static/js/state.js +43 -0
  62. sql_assistant-1.0.0/src/sql_assistant/web/static/js/theme-manager.js +64 -0
  63. sql_assistant-1.0.0/src/sql_assistant/web/static/js/ui.js +53 -0
  64. sql_assistant-1.0.0/src/sql_assistant/web/templates/index.html +373 -0
  65. sql_assistant-1.0.0/start.py +4 -0
@@ -0,0 +1,116 @@
1
+ # ====================
2
+ # Virtual Environment
3
+ # ====================
4
+ .venv/
5
+ .env/
6
+ env/
7
+ venv/
8
+
9
+ # ====================
10
+ # Python
11
+ # ====================
12
+ __pycache__/
13
+ *.pyc
14
+ *.pyo
15
+ *.pyd
16
+ .Python
17
+ *.egg-info/
18
+ uv.lock
19
+
20
+ # ====================
21
+ # Build Artifacts
22
+ # ====================
23
+ dist/
24
+ build/
25
+ *.whl
26
+
27
+ # ====================
28
+ # IDE
29
+ # ====================
30
+ .vscode/
31
+ .idea/
32
+ *.swp
33
+ *.swo
34
+ *~
35
+
36
+ # ====================
37
+ # OS
38
+ # ====================
39
+ .DS_Store
40
+ Thumbs.db
41
+ desktop.ini
42
+
43
+ # ====================
44
+ # Logs
45
+ # ====================
46
+ *.log
47
+ logs/
48
+ *.log.*
49
+
50
+ # ====================
51
+ # Configuration
52
+ # ====================
53
+ # 项目数据目录(配置和数据库)
54
+ .data/
55
+ # 旧版配置路径(如存在)
56
+ ~/.sql-assistant/
57
+ .sql-assistant/
58
+
59
+ # ====================
60
+ # Backup
61
+ # ====================
62
+ # 数据库备份目录
63
+ backups/
64
+
65
+ # ====================
66
+ # Database
67
+ # ====================
68
+ # 注意:.data 目录下的数据库已在上方排除
69
+ # 忽略其他位置的数据库文件
70
+ *.db
71
+ *.sqlite
72
+ *.sqlite3
73
+ *.db-journal
74
+
75
+ # ====================
76
+ # Trae IDE
77
+ # ====================
78
+ .codegraph/
79
+ ${APPDATA}/
80
+
81
+ # ====================
82
+ # DeepSeek
83
+ # ====================
84
+ .deepseek/
85
+
86
+ # ====================
87
+ # Node.js (if any)
88
+ # ====================
89
+ node_modules/
90
+ package-lock.json
91
+ yarn.lock
92
+ pnpm-lock.yaml
93
+
94
+ # ====================
95
+ # Testing
96
+ # ====================
97
+ .coverage
98
+ htmlcov/
99
+ .pytest_cache/
100
+ .tox/
101
+ test-results/
102
+
103
+ # ====================
104
+ # Security
105
+ # ====================
106
+ *.pem
107
+ *.key
108
+ *.cert
109
+ secrets/
110
+
111
+ # ====================
112
+ # Misc
113
+ # ====================
114
+ .cache/
115
+ *.egg
116
+ .installed.cfg
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 fjz-hosts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: sql-assistant
3
+ Version: 1.0.0
4
+ Summary: SQL 智能助手 - 自然语言转 SQL 查询工具,支持主流数据库和 LLM
5
+ License-File: LICENSE
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: aiosqlite>=0.20.0
8
+ Requires-Dist: fastapi>=0.110.0
9
+ Requires-Dist: httpx>=0.27.0
10
+ Requires-Dist: jinja2>=3.1.0
11
+ Requires-Dist: psycopg2-binary>=2.9.0
12
+ Requires-Dist: pydantic>=2.0.0
13
+ Requires-Dist: pymongo>=4.6.0
14
+ Requires-Dist: pymysql>=1.1.0
15
+ Requires-Dist: python-multipart>=0.0.9
16
+ Requires-Dist: pyyaml>=6.0
17
+ Requires-Dist: redis>=5.0.0
18
+ Requires-Dist: uvicorn[standard]>=0.29.0
19
+ Provides-Extra: claude
20
+ Requires-Dist: anthropic>=0.30.0; extra == 'claude'
21
+ Provides-Extra: gemini
22
+ Requires-Dist: google-generativeai>=0.8.0; extra == 'gemini'
23
+ Provides-Extra: sqlserver
24
+ Requires-Dist: pymssql>=2.3.0; extra == 'sqlserver'
@@ -0,0 +1,447 @@
1
+ # SQL Smart Assistant
2
+
3
+ <p align="center">
4
+ <img src="https://api.iconify.design/vscode-icons/file-type-sql.svg" alt="SQL Assistant" width="64"/>
5
+ </p>
6
+
7
+ <p align="center">
8
+ Natural Language → SQL → Query Results
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square" alt="License: MIT"/></a>
13
+ <img src="https://img.shields.io/badge/Python-3.10-blue?style=flat-square&logo=python" alt="Python"/>
14
+ <img src="https://img.shields.io/badge/FastAPI-0.100-009688?style=flat-square&logo=fastapi" alt="FastAPI"/>
15
+ <img src="https://img.shields.io/badge/MySQL-8.0-blue?style=flat-square&logo=mysql" alt="MySQL"/>
16
+ <img src="https://img.shields.io/badge/PostgreSQL-15-blue?style=flat-square&logo=postgresql" alt="PostgreSQL"/>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <a href="#quick-start">Quick Start</a> · <a href="#features">Features</a> · <a href="#system-architecture">Architecture</a> · <a href="#project-structure">Structure</a> · <a href="#configuration">Configuration</a>
21
+ </p>
22
+
23
+
24
+ ## 🗞️ News
25
+
26
+ - **2026-05-10** — 🎉 SQL Smart Assistant v1.0.0 released!
27
+
28
+
29
+ ## 📖 Overview
30
+
31
+ **SQL Smart Assistant** is an intelligent database query tool based on large language models, supporting natural language to SQL conversion, multi-database connection management, query history records, and more.
32
+
33
+ ### Highlights
34
+
35
+ - **Natural Language to SQL**: Describe query requirements in Chinese/English, AI automatically generates and executes SQL
36
+ - **Multi-database Support**: MySQL / SQL Server / PostgreSQL / Redis / MongoDB
37
+ - **Multi-LLM Support**: DeepSeek / Doubao / Kimi / Qwen / OpenAI / Gemini / Claude / GLM / MiniMax / SiliconFlow / OpenRouter / Grok / Tencent / Mimo / Ollama
38
+ - **Conversation Management**: Create, delete, switch, rename conversation sessions
39
+ - **Theme Customization**: Light/dark theme switch, 8 theme colors available
40
+ - **Configuration UI**: Manage LLM API Key and database connections directly in Web UI
41
+ - **Streaming Response**: SSE streaming output for real-time LLM generation viewing
42
+ - **Data Persistence**: SQLite local storage, unified configuration file management
43
+
44
+
45
+ ## <a id="quick-start"></a> 🚀 Quick Start
46
+
47
+ ### Prerequisites
48
+
49
+ - **Python** >= 3.10
50
+
51
+ ### Option 1: Install from GitHub Release (Recommended)
52
+
53
+ Download and install directly from the Release page:
54
+
55
+ ```bash
56
+ # Install latest version (replace with your Release URL)
57
+ pip install https://github.com/fjz-hosts/sql-assistant/releases/download/sql-assistant-v1.0.0/sql_assistant-1.0.0-py3-none-any.whl
58
+
59
+ # Install with optional dependencies
60
+ pip install "sql-assistant[sqlserver,gemini,claude]"
61
+ ```
62
+
63
+ ### Option 2: Install from Source (Development Mode)
64
+
65
+ ```bash
66
+ git clone https://github.com/fjz-hosts/sql-assistant.git
67
+ cd sql-assistant
68
+
69
+ # Install uv tool
70
+ pip install uv
71
+
72
+ # Create virtual environment and install dependencies
73
+ uv venv
74
+ uv pip install -e .
75
+ ```
76
+
77
+ ### Start Server
78
+
79
+ ```bash
80
+ # Option 1: Use CLI command (Recommended)
81
+ sql-assistant
82
+
83
+ # Option 2: Use Python module
84
+ python -m sql_assistant.main
85
+
86
+ # Option 3: Use uvicorn directly (with custom parameters)
87
+ uvicorn sql_assistant.main:app --host 0.0.0.0 --port 8000
88
+ ```
89
+
90
+ ### Open Browser
91
+
92
+ Visit **http://localhost:5010** to start using!
93
+
94
+ ### Initial Configuration
95
+
96
+ 1. Click the ⚙️ Settings button on the left
97
+ 2. Add your API Key in "LLM Configuration"
98
+ 3. Add database connections in "Database Configuration"
99
+ 4. Click "Activate" to select your preferred LLM and database
100
+ 5. Start querying!
101
+
102
+
103
+ ## <a id="features"></a> ✨ Features
104
+
105
+ ### 1. Natural Language to SQL
106
+
107
+ - **Smart SQL Generation**: Convert natural language descriptions into executable SQL statements based on large language models
108
+ - **Multi-language Support**: Supports Chinese and English query descriptions
109
+ - **Context Awareness**: Generates accurate SQL based on database table structure
110
+
111
+ ### 2. Multi-database Connections
112
+
113
+ - **MySQL**: Full support for SELECT / INSERT / UPDATE / DELETE operations
114
+ - **SQL Server**: Supports Windows Authentication and SQL Authentication
115
+ - **PostgreSQL**: Supports SSL connections and advanced features
116
+ - **Redis**: Supports Redis command execution and data query
117
+ - **MongoDB**: Supports NoSQL queries and document operations
118
+
119
+ ### 3. Conversation Management
120
+
121
+ - **Multi-session Support**: Create multiple independent conversations, each with its own query history
122
+ - **Rename Conversation**: Double-click conversation title or click pencil icon to rename
123
+ - **Delete Conversation**: Click trash icon to delete conversation and associated history
124
+ - **Smart Naming**: Automatically uses the first question as title when creating new conversation
125
+
126
+ ### 5. Theme Customization
127
+
128
+ - **Light/Dark Mode**: One-click switch between light and dark themes
129
+ - **8 Theme Colors**: Blue, Purple, Pink, Red, Orange, Yellow, Green, Cyan
130
+ - **Theme Memory**: Automatically remembers user theme preferences
131
+
132
+ ### 6. Web Configuration Interface
133
+
134
+ - **LLM Configuration Management**: Add, edit, delete LLM API Keys
135
+ - **Database Configuration Management**: Add, edit, delete database connections
136
+ - **Active Status Switch**: One-click switch between current LLM and database
137
+
138
+ ### 7. Database Backup
139
+
140
+ - **Full Backup**: Backup all table structures and data
141
+ - **Incremental Backup**: Backup only newly added or modified data since last backup (requires timestamp field in tables)
142
+ - **Selective Backup**: Support specifying partial tables for backup, backup all tables by default
143
+ - **Backup Management**: View backup list, get backup details, delete backup files
144
+ - **Data Recovery**: Restore table structure and data from backup files to current database
145
+
146
+
147
+ ## <a id="system-architecture"></a> 🏗️ System Architecture
148
+
149
+ ### Overall Architecture Diagram
150
+
151
+ ```
152
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
153
+ │ Frontend Layer│ │ Business Layer│ │ Data Storage │
154
+ │ - HTML/CSS/JS │◄──►│ - FastAPI │◄──►│ - SQLite(Config)│
155
+ │ - Vue.js │ │ - LLM Manager │ │ - MySQL/PG/SQL │
156
+ │ - Tailwind CSS │ │ - DB Connector │ │ Server/Mongo │
157
+ └─────────────────┘ └─────────────────┘ └─────────────────┘
158
+ │ │ │
159
+ ▼ ▼ ▼
160
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
161
+ │ User Interaction│ │ AI Services │ │ Query History │
162
+ │ - NL Input │ │ - DeepSeek │ │ - SQLite Storage│
163
+ │ - SQL Display │ │ - Doubao/Kimi │ │ - History Review│
164
+ │ - Result Display│ │ - Qwen │ │ │
165
+ └─────────────────┘ │ - OpenAI │ └─────────────────┘
166
+ │ - Gemini/Claude│
167
+ └─────────────────┘
168
+ ```
169
+
170
+ ### LLM Provider Integration
171
+
172
+ | Provider | Model Series | API Type |
173
+ |----------|--------------|----------|
174
+ | **DeepSeek** | deepseek-v4-pro, deepseek-v4-flash | OpenAI Compatible |
175
+ | **Doubao** | doubao-seed-2-0-pro-260215, doubao-seed-2-0-lite-260215, doubao-seed-2-0-mini-260215, doubao-seed-1-8-251228 | OpenAI Compatible |
176
+ | **Kimi** | kimi-k2.6, kimi-k2.5, kimi-k2-thinking | OpenAI Compatible |
177
+ | **Qwen** | qwen3.6-max-preview, qwen3.6-plus, qwen3.6-flash, qwen3.5-flash, qwen3.5-plus, qwen3-max, qwen3-vl-plus | OpenAI Compatible |
178
+ | **OpenAI** | gpt-5.5, gpt-5.4-pro, gpt-5.4-mini, gpt-5.4-nano, gpt-4o, gpt-4o-mini, gpt-4-turbo, gpt-4.1, gpt-4, gpt-3.5-turbo, o1-preview, o1-mini | OpenAI Native |
179
+ | **Gemini** | gemini-3.1-pro-preview, gemini-3-flash-preview, gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, gemini-1.5-pro, gemini-1.5-flash | Google API |
180
+ | **Claude** | claude-opus-4-7, claude-opus-4-6, claude-sonnet-4-6, claude-sonnet-4-5, claude-haiku-4-5, claude-3-opus, claude-3-sonnet, claude-3-haiku | Anthropic API |
181
+ | **GLM** | glm-5.1, glm-5v-turbo, glm-5, glm-4.7, glm-4.6 | OpenAI Compatible |
182
+ | **MiniMax** | MiniMax-M2.7 | Anthropic API |
183
+ | **SiliconFlow** | deepseek-ai/DeepSeek-V3.2, deepseek-ai/DeepSeek-R1, Qwen/Qwen3-VL-32B-Instruct, THUDM/GLM-4.1V-9B-Thinking | OpenAI Compatible |
184
+ | **OpenRouter** | deepseek/deepseek-v4-pro, deepseek/deepseek-v4-flash | OpenAI Compatible |
185
+ | **Grok** | grok-4.20-reasoning, grok-4.20, grok-4-1-fast-reasoning, grok-code-fast-1 | OpenAI Compatible |
186
+ | **Tencent** | hy3-preview | OpenAI Compatible |
187
+ | **Mimo** | mimo-v2.5-pro, mimo-v2.5 | OpenAI Compatible |
188
+ | **Ollama** | llama3.3, gemma3, deepseek-r1 | OpenAI Compatible |
189
+
190
+ ### Database Connectors
191
+
192
+ | Database | Connector Module | Supported Operations |
193
+ |----------|------------------|---------------------|
194
+ | **MySQL** | `mysql.py` | SELECT/INSERT/UPDATE/DELETE |
195
+ | **SQL Server** | `sqlserver.py` | SELECT/INSERT/UPDATE/DELETE |
196
+ | **PostgreSQL** | `postgresql.py` | SELECT/INSERT/UPDATE/DELETE |
197
+ | **Redis** | `redis.py` | Redis Command Execution |
198
+ | **MongoDB** | `mongodb.py` | NoSQL Query Operations |
199
+
200
+
201
+ ## <a id="project-structure"></a> 📁 Project Structure
202
+
203
+ ```
204
+ SQL Assistant/
205
+ ├── pyproject.toml # Python project configuration (dependency management)
206
+ ├── README.md # Project documentation
207
+ ├── LICENSE # MIT License
208
+ ├── backups/ # Database backup storage directory
209
+ │ └── full_20260101_120000/ # Timestamp-named backup folder
210
+ │ ├── metadata.json # Backup metadata
211
+ │ ├── users_schema.json # Table schema file
212
+ │ └── users_data.json # Table data file
213
+ ├── .data/ # Data storage directory
214
+ │ ├── config.yaml # Configuration file (API Key, etc.)
215
+ │ └── history.db # SQLite database (query history)
216
+ ├── .venv/ # uv virtual environment
217
+ └── src/
218
+ └── sql_assistant/
219
+ ├── __init__.py # Package initialization
220
+ ├── main.py # FastAPI entry
221
+ ├── config.py # Configuration management (YAML)
222
+ ├── settings.py # Configuration data models
223
+ ├── api/ # API module
224
+ │ ├── __init__.py
225
+ │ ├── routes.py # API routes
226
+ │ ├── models.py # Pydantic models
227
+ │ └── dependencies.py # Dependency injection
228
+ ├── llm/ # LLM module
229
+ │ ├── __init__.py
230
+ │ ├── manager.py # LLM manager
231
+ │ ├── base.py # Provider abstract base class
232
+ │ ├── prompts.py # SQL Prompt templates
233
+ │ └── providers/ # LLM provider implementations
234
+ │ ├── __init__.py
235
+ │ ├── openai_compatible.py # DeepSeek/Doubao/Kimi/Qwen/OpenAI
236
+ │ ├── gemini.py # Google Gemini
237
+ │ └── claude.py # Anthropic Claude
238
+ ├── database/ # Database module
239
+ │ ├── __init__.py
240
+ │ ├── manager.py # Database connection manager
241
+ │ ├── history.py # Query history (SQLite)
242
+ │ ├── backup.py # Database backup module
243
+ │ └── connectors/ # Database connectors
244
+ │ ├── __init__.py
245
+ │ ├── base.py # Connector abstract base class
246
+ │ ├── mysql.py
247
+ │ ├── sqlserver.py
248
+ │ ├── postgresql.py
249
+ │ ├── redis.py
250
+ │ └── mongodb.py
251
+ └── web/ # Web frontend
252
+ ├── __init__.py
253
+ ├── templates/ # HTML templates
254
+ │ └── index.html # Main page
255
+ └── static/ # Static resources
256
+ ├── css/
257
+ │ ├── theme.css # Theme styles (CSS variables)
258
+ │ └── style.css # Application styles
259
+ └── js/
260
+ ├── theme-manager.js # Theme switching logic
261
+ ├── color-theme-manager.js # Theme color switching logic
262
+ └── app.js # Application main logic
263
+ ```
264
+
265
+
266
+ ## <a id="configuration"></a> 🔧 Configuration
267
+
268
+ ### Configuration File Location
269
+
270
+ Configuration files and data storage have been migrated to the project `.data` directory:
271
+
272
+ ```
273
+ SQL Assistant/
274
+ └── .data/
275
+ ├── config.yaml # Configuration file (API Key, etc.)
276
+ └── history.db # SQLite database (query history)
277
+ ```
278
+
279
+ > ⚠️ **Note**: Configuration files stored in `~/.sql-assistant/` from older versions need to be manually migrated to the project `.data` directory.
280
+
281
+ ### Database Backup Storage
282
+
283
+ Database backup files are stored in the `backups/` folder at the project root:
284
+
285
+ ```
286
+ SQL Assistant/
287
+ └── backups/
288
+ ├── .last_backup_timestamp # Incremental backup timestamp marker
289
+ ├── full_20260101_120000/ # Full backup
290
+ │ ├── metadata.json # Backup metadata (type, table count, record count, etc.)
291
+ │ ├── users_schema.json # users table schema
292
+ │ └── users_data.json # users table data
293
+ └── incremental_20260102_120000/ # Incremental backup
294
+ ├── metadata.json
295
+ ├── orders_schema.json
296
+ └── orders_data.json
297
+ ```
298
+
299
+ Backup File Description:
300
+ - `metadata.json`: Contains backup type, database information, table count, total records, backup time, and other metadata
301
+ - `*_schema.json`: Table structure information (column names, types, key information, etc.)
302
+ - `*_data.json`: Table data content (JSON format)
303
+ - `.last_backup_timestamp`: Records the timestamp of the last incremental backup
304
+
305
+ ### Configuration Options
306
+
307
+ ```yaml
308
+ # Currently active LLM provider
309
+ active_llm: deepseek
310
+
311
+ # Currently active database connection
312
+ active_database: mysql_dev
313
+
314
+ # LLM provider configurations
315
+ llm_providers:
316
+ deepseek:
317
+ api_key: "your_api_key"
318
+ api_base: "https://api.deepseek.com/v1"
319
+ model: "deepseek-moe"
320
+ doubao:
321
+ api_key: "your_api_key"
322
+ api_base: "https://ark.cn-beijing.volces.com/api/v3"
323
+ model: "doubao-seed-2-0-pro-260215"
324
+ kimi:
325
+ api_key: "your_api_key"
326
+ api_base: "https://api.moonshot.cn/v1"
327
+ model: "kimi-k2.6"
328
+ qwen:
329
+ api_key: "your_api_key"
330
+ api_base: "https://dashscope.aliyuncs.com/compatible-mode/v1"
331
+ model: "qwen3.6-plus"
332
+ openai:
333
+ api_key: "your_api_key"
334
+ api_base: "https://api.openai.com/v1"
335
+ model: "gpt-5.5"
336
+ gemini:
337
+ api_key: "your_api_key"
338
+ model: "gemini-2.0-pro"
339
+ claude:
340
+ api_key: "your_api_key"
341
+ model: "claude-sonnet-4-6"
342
+
343
+ # Database connection configurations
344
+ database_connections:
345
+ mysql_dev:
346
+ type: mysql
347
+ host: localhost
348
+ port: 3306
349
+ database: your_database
350
+ username: your_username
351
+ password: your_password
352
+ postgresql_prod:
353
+ type: postgresql
354
+ host: localhost
355
+ port: 5432
356
+ database: your_database
357
+ username: your_username
358
+ password: your_password
359
+ sqlserver_prod:
360
+ type: sqlserver
361
+ host: localhost
362
+ port: 1433
363
+ database: your_database
364
+ username: your_username
365
+ password: your_password
366
+ redis_cache:
367
+ type: redis
368
+ host: localhost
369
+ port: 6379
370
+ db: 0
371
+ mongodb_prod:
372
+ type: mongodb
373
+ host: localhost
374
+ port: 27017
375
+ database: your_database
376
+ username: your_username
377
+ password: your_password
378
+ ```
379
+
380
+ ### Additional Dependencies Installation
381
+
382
+ Some databases and LLMs require additional dependencies:
383
+
384
+ ```bash
385
+ # SQL Server support
386
+ uv pip install pymssql
387
+
388
+ # Google Gemini support
389
+ uv pip install google-generativeai
390
+
391
+ # Anthropic Claude support
392
+ uv pip install anthropic
393
+
394
+ # MongoDB support
395
+ uv pip install pymongo
396
+
397
+ # PostgreSQL support
398
+ uv pip install psycopg2-binary
399
+ ```
400
+
401
+
402
+ ## 📈 API Documentation
403
+
404
+ Visit **http://localhost:5010/docs** after starting the service to view Swagger API documentation.
405
+
406
+ ### Main API Endpoints
407
+
408
+ | Endpoint | Method | Description |
409
+ |----------|--------|-------------|
410
+ | `/api/query` | POST | Execute natural language query |
411
+ | `/api/conversations` | GET/POST | Get conversation list / Create new conversation |
412
+ | `/api/conversations/{id}` | GET/PUT/DELETE | Get/update/delete single conversation |
413
+ | `/api/config/llm` | GET/POST | LLM configuration management |
414
+ | `/api/config/database` | GET/POST | Database configuration management |
415
+ | `/api/config/active` | GET/PUT | Active configuration management |
416
+ | `/api/history` | GET | Query history list |
417
+ | `/api/backup` | POST | Create database backup |
418
+ | `/api/backup/list` | GET | Get backup list |
419
+ | `/api/backup/{backup_id}` | GET/DELETE | Get backup details / Delete backup |
420
+ | `/api/backup/restore` | POST | Restore database from backup |
421
+
422
+
423
+ ## ⚠️ Notes
424
+
425
+ - **Data Directory**: Configuration files and database have been moved to the project `.data` directory, ensure proper permissions for this directory
426
+ - **API Key Security**: All configurations are stored in `.data/config.yaml`, regular backups are recommended
427
+ - **Dangerous Operation Warning**: Confirm WHERE clause before executing DELETE/UPDATE
428
+ - **Database Permissions**: It is recommended to use a read-only database user for query operations
429
+ - **Network Security**: It is recommended to use HTTPS protocol in production environment
430
+
431
+
432
+ ## 🤝 Contributing
433
+
434
+ Community contributions are welcome! Whether it's bug reports, feature suggestions, or code submissions, they are all highly appreciated.
435
+
436
+ ### Contribution Process
437
+
438
+ 1. Fork the repository
439
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
440
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
441
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
442
+ 5. Open a Pull Request
443
+
444
+
445
+ ## 📄 License
446
+
447
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,34 @@
1
+ [project]
2
+ name = "sql-assistant"
3
+ version = "1.0.0"
4
+ description = "SQL 智能助手 - 自然语言转 SQL 查询工具,支持主流数据库和 LLM"
5
+ requires-python = ">=3.10"
6
+ dependencies = [
7
+ "fastapi>=0.110.0",
8
+ "uvicorn[standard]>=0.29.0",
9
+ "jinja2>=3.1.0",
10
+ "pydantic>=2.0.0",
11
+ "python-multipart>=0.0.9",
12
+ "pyyaml>=6.0",
13
+ "httpx>=0.27.0",
14
+ "pymysql>=1.1.0",
15
+ "psycopg2-binary>=2.9.0",
16
+ "redis>=5.0.0",
17
+ "pymongo>=4.6.0",
18
+ "aiosqlite>=0.20.0",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ sqlserver = ["pymssql>=2.3.0"]
23
+ gemini = ["google-generativeai>=0.8.0"]
24
+ claude = ["anthropic>=0.30.0"]
25
+
26
+ [build-system]
27
+ requires = ["hatchling"]
28
+ build-backend = "hatchling.build"
29
+
30
+ [tool.hatch.build.targets.wheel]
31
+ packages = ["src/sql_assistant"]
32
+
33
+ [project.scripts]
34
+ sql-assistant = "sql_assistant.main:main"
@@ -0,0 +1,3 @@
1
+ """SQL 智能助手 - 自然语言转 SQL 查询工具"""
2
+
3
+ __version__ = "1.0.0"
@@ -0,0 +1 @@
1
+ """API 路由模块"""