AI数据库管理工具

DB Explorer是一款由Vercel AI SDK和Google Gemini 2.5 Flash驱动的现代数据库探索工具,支持自然语言查询和实时数据流处理。

  • by chiraggahujaa
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 chiraggahujaa/db-explorer

使用说明

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_indexes
  • analyze_foreign_keys, get_table_dependencies

数据查询

  • select_data, count_records, find_by_id, search_records
  • get_recent_records, execute_custom_query

数据修改

  • insert_record, update_record, delete_record, bulk_insert

分析与关系

  • join_tables, find_orphaned_records, validate_referential_integrity
  • analyze_table_relationships, get_column_statistics

公用设施和维护

  • explain_query, check_table_status, optimize_table
  • test_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,以实现更准确的查询:

  1. 连接到您的数据库
  2. 点击“列车模式”按钮
  3. AI学习你的表结构、关系和约束
  4. 获得更好的查询建议和验证

上下文管理

  • 自动文摘:长对话会自动摘要
  • 上下文窗口跟踪:上下文使用情况的视觉指示器
  • 隐式缓存:Gemini 2.5 Flash缓存重复内容以节省成本

聊天记录

  • 持续会话:随时恢复对话
  • 标题生成:AI为聊天生成有意义的标题
  • 多连接支持:每个数据库单独的聊天历史记录

🐛 故障排除

前端连接问题:

  1. 验证后端是否正在运行: curl http://localhost:5000/health
  2. 检查 NEXT_PUBLIC_API_URL 前端 .env.local
  3. 查看浏览器控制台是否有错误

AI API错误:

  1. 从获取Gemini API密钥https://aistudio.google.com/app/apikey
  2. 集 NEXT_PUBLIC_GEMINI_API_KEY 前端 .env.local
  3. 重新启动开发服务器

数据库连接问题:

  1. 在后端验证数据库凭据 .env
  2. 检查Supabase连接状态
  3. 从UI测试连接

📚 文档

🤝 贡献

  1. 分叉存储库
  2. 创建特征分支(git checkout -b feature/amazing-feature)
  3. 提交更改(git commit -m 'Add amazing feature')
  4. 推送到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

📄 许可证

MIT许可证-有关详细信息,请参阅许可证文件


由...制作❤️ 适用于使用Vercel AI SDK的数据库开发人员