DB Explorer-基于AI的数据库管理
一款现代数据库探索工具,具有由Vercel AI SDK和Google Gemini 2.5 Flash支持的自然语言查询功能。
🌟 特性
- 🤖 自然语言查询 -使用Gemini 2.5 Flash用简单的英语提问
- ⚡ 实时流媒体 -使用Vercel AI SDK查看AI响应
- 🔒 智能上下文管理 -长对话的自动上下文摘要
- 🎨 现代用户界面 -干净、专业的界面,暗模式
- 🚀 动态连接 -动态配置数据库
- 📊 42+数据库工具 -使用人工智能工具查询、修改和分析数据
- 💾 模式预培训 -在数据库模式上训练AI以获得更好的查询
- 🎯 上下文缓存 -Gemini 2.5 Flash的隐式缓存可降低75%的成本
🏗️ 建筑
Frontend (Next.js) ━━━ API Route (/api/chat) ━━━ Gemini 2.5 Flash
↓
Backend (Express) ━━━ Database Tools ━━━ Multi-DB Support
(Auth & Connections)🚀 快速开始
先决条件
- Node.js 18+
- 数据库 (PostgreSQL、MySQL、SQLite或Supabase)
- Gemini API密钥 (从 谷歌AI工作室)
安装
# 1. Start Backend API
cd db-explorer-api
npm install
cp .env.example .env
# Configure your Supabase credentials in .env
npm run dev # http://localhost:5000
# 2. Start Frontend
cd db-explorer-web
npm install
cp .env.example .env.local
# Add your Gemini API key to .env.local
npm run dev # http://localhost:3000📝 配置
后端(.env)
备注:使用单个 .env 文件适用于所有环境。这 NODE_ENV npm脚本中的变量用于运行时行为,而不是用于加载不同的文件。
SUPABASE_URL=your-supabase-url
SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-key
JWT_SECRET=your-jwt-secret
FRONTEND_URL=http://localhost:3000前端(.env.local)
# API Configuration
NEXT_PUBLIC_API_URL=http://localhost:5000
# Google Gemini API Key (Required)
# Get from: https://aistudio.google.com/app/apikey
NEXT_PUBLIC_GEMINI_API_KEY=your-gemini-api-key
# Google OAuth (Optional)
NEXT_PUBLIC_GOOGLE_CLIENT_ID=your-google-client-id💬 使用示例
自然语言:
Show me all users created in the last 7 days
Find customers with orders over $1000
What are the foreign key relationships in this database?SQL查询:
SELECT * FROM orders WHERE total > 1000 LIMIT 10模式探索:
Show me all tables in this database
Describe the users table structure🔒 安全功能
- JWT认证:安全的用户身份验证和授权
- 基于角色的访问:连接的所有者、管理员和查看者角色
- 查询验证:AI驱动的查询安全检查
- 可配置保护:只读模式,查询限制
📊 可用的AI工具(42+)
架构与结构
list_databases,list_tables,describe_table,show_indexesanalyze_foreign_keys,get_table_dependencies
数据查询
select_data,count_records,find_by_id,search_recordsget_recent_records,execute_custom_query
数据修改
insert_record,update_record,delete_record,bulk_insert
分析与关系
join_tables,find_orphaned_records,validate_referential_integrityanalyze_table_relationships,get_column_statistics
公用设施和维护
explain_query,check_table_status,optimize_tabletest_connection,get_database_size
🔧 技术栈
- 前端:Next.js 15、React 19、TailwindCSS、Zustand、Vercel AI SDK
- 后端:Express 5、Supabase、JWT、TypeScript
- 人工智能:Gemini 2.5 Flash,配备42多种数据库工具
- 数据库:MySQL、PostgreSQL、SQLite、Supabase
🎯 主要特点
模式预培训
在数据库模式上训练AI,以实现更准确的查询:
- 连接到您的数据库
- 点击“列车模式”按钮
- AI学习你的表结构、关系和约束
- 获得更好的查询建议和验证
上下文管理
- 自动文摘:长对话会自动摘要
- 上下文窗口跟踪:上下文使用情况的视觉指示器
- 隐式缓存:Gemini 2.5 Flash缓存重复内容以节省成本
聊天记录
- 持续会话:随时恢复对话
- 标题生成:AI为聊天生成有意义的标题
- 多连接支持:每个数据库单独的聊天历史记录
🐛 故障排除
前端连接问题:
- 验证后端是否正在运行:
curl http://localhost:5000/health - 检查
NEXT_PUBLIC_API_URL前端.env.local - 查看浏览器控制台是否有错误
AI API错误:
- 从获取Gemini API密钥https://aistudio.google.com/app/apikey
- 集
NEXT_PUBLIC_GEMINI_API_KEY前端.env.local - 重新启动开发服务器
数据库连接问题:
- 在后端验证数据库凭据
.env - 检查Supabase连接状态
- 从UI测试连接
📚 文档
🤝 贡献
- 分叉存储库
- 创建特征分支(
git checkout -b feature/amazing-feature) - 提交更改(
git commit -m 'Add amazing feature') - 推送到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
MIT许可证-有关详细信息,请参阅许可证文件
______________________________________________________________________
由...制作❤️ 适用于使用Vercel AI SDK的数据库开发人员
