Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Transform natural language into powerful database queries through an intuitive web interface that:

- **Understands Context**: Interprets user intent from conversational prompts
- **Supports Multiple Databases**: Works with SQLAlchemy and Snowflake databases
- **Supports Multiple Databases**: Works with SQLAlchemy, Snowflake, and SQLite databases (backend implementation required)
- **Provides Real-time Results**: Shows query results instantly in formatted tables
- **Handles Errors Gracefully**: Offers helpful error messages and suggestions

Expand Down Expand Up @@ -141,6 +141,57 @@ This repository is participating in **Hacktoberfest 2025**! We welcome contribut
4. **Open your browser**
Navigate to [http://localhost:3000](http://localhost:3000)

### SQLite Local Development Setup

For local development with SQLite, follow these additional steps:

1. **Set up environment variables** for SQLite:

```bash
# Create .env.local file
DATABASE_TYPE=sqlite
DATABASE_URL=sqlite:///local_dev.db
```

2. **Initialize the SQLite database** (requires Python and SQLAlchemy):

```bash
# Install Python dependencies (if not already installed)
pip install sqlalchemy

# Initialize database
python scripts/init_sqlite.py

# Optional: Add sample data
python scripts/seed_data.py
```

3. **Configure your MCP server** to use SQLite backend

**⚠️ Important**: The MCP-DB Connector server must be updated to support SQLite queries. The frontend now accepts SQLite as a target, but the backend server needs corresponding SQLite support.

4. **Start both servers**:

```bash
# Terminal 1: Start MCP server (with SQLite support)
# Your MCP server command here

# Terminal 2: Start Next.js development server
npm run dev
```

**SQLite Benefits for Development:**
- No external database server required
- File-based storage (`local_dev.db`)
- Easy to reset and recreate
- Perfect for testing and development

**SQLite Limitations:**
- Single-writer concurrency (not suitable for high-traffic production)
- No built-in user authentication or permissions
- Limited data types compared to PostgreSQL/MySQL
- File-based (backup and replication require manual processes)

### Usage

#### Database Console
Expand All @@ -152,8 +203,9 @@ Navigate to `/db-console` to access the database query interface:
- Example: "Find the top 10 products by sales"

2. **Select Database Target**: Choose between:
- **SQLAlchemy**: For SQLAlchemy-based applications
- **Snowflake**: For Snowflake data warehouse
- **SQLAlchemy**: For SQLAlchemy-based applications
- **Snowflake**: For Snowflake data warehouse
- **SQLite**: For local development with SQLite database

3. **Execute Query**: Click "Execute Query" to run your prompt

Expand Down Expand Up @@ -188,7 +240,7 @@ Execute a database query using natural language.
```json
{
"prompt": "string",
"target": "sqlalchemy" | "snowflake"
"target": "sqlalchemy" | "snowflake" | "sqlite"
}
```

Expand Down
4 changes: 2 additions & 2 deletions app/api/db/[query]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export async function POST(
}

// Validate target value
if (!['sqlalchemy', 'snowflake'].includes(body.target)) {
if (!['sqlalchemy', 'snowflake', 'sqlite'].includes(body.target)) {
const errorResponse: DatabaseErrorResponse = {
success: false,
error: 'Invalid target: must be either "sqlalchemy" or "snowflake"'
error: 'Invalid target: must be either "sqlalchemy", "snowflake", or "sqlite"'
};
return NextResponse.json(errorResponse, { status: 400 });
}
Expand Down
3 changes: 2 additions & 1 deletion app/components/DbConsole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DatabaseTarget, DatabaseQueryResponse } from '@/app/types/database';
* A reusable component for database query interface
* Features:
* - Natural language prompt input
* - Database target selection (SQLAlchemy or Snowflake)
* - Database target selection (SQLAlchemy, Snowflake, or SQLite)
* - Query submission with loading states
* - Results display in a styled table
* - Error handling and user feedback
Expand Down Expand Up @@ -198,6 +198,7 @@ export default function DbConsole() {
>
<option value="sqlalchemy">SQLAlchemy</option>
<option value="snowflake">Snowflake</option>
<option value="sqlite">SQLite</option>
</select>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/types/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Database target types
export type DatabaseTarget = 'sqlalchemy' | 'snowflake';
export type DatabaseTarget = 'sqlalchemy' | 'snowflake' | 'sqlite';

// API request types
export interface DatabaseQueryRequest {
Expand Down
52 changes: 50 additions & 2 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,61 @@ Create a `.env.local` file with the following variables:
# MCP Server Configuration
MCP_SERVER_URL=http://localhost:8000

# Database Configuration (if needed)
DATABASE_URL=your_database_url
# Database Configuration
# For SQLite local development (recommended)
DATABASE_TYPE=sqlite
DATABASE_URL=sqlite:///local_dev.db

# For production databases (uncomment as needed)
# DATABASE_TYPE=sqlalchemy
# DATABASE_URL=postgresql://user:password@localhost:5432/dbname

# Development Configuration
NODE_ENV=development
```

## SQLite Development Setup

For local development with SQLite, additional setup is required:

### Prerequisites

- **Python** 3.8+ (for database scripts)
- **SQLAlchemy** (install with `pip install sqlalchemy`)
- **MCP-DB Connector server** with SQLite support

### Database Initialization

1. **Initialize SQLite database**:

```bash
python scripts/init_sqlite.py
```

2. **Optional: Add sample data**:

```bash
python scripts/seed_data.py
```

3. **Configure MCP server** to connect to SQLite database

**⚠️ Backend Requirement**: The MCP-DB Connector server must be updated separately to handle SQLite queries. The frontend changes allow selecting SQLite as a target, but the backend server needs corresponding implementation.

### SQLite Benefits

- **No external dependencies**: File-based database
- **Easy reset**: Delete `local_dev.db` to start fresh
- **Fast setup**: No server installation required
- **Development focused**: Perfect for testing and prototyping

### Database Scripts

- `scripts/init_sqlite.py`: Creates database schema
- `scripts/seed_data.py`: Populates with sample data

Both scripts are idempotent and can be run multiple times safely.

## Debugging

### Common Issues
Expand Down
19 changes: 17 additions & 2 deletions docs/ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,23 @@ Copy this file to `.env.local` and update the values for your environment.
# MCP Server Configuration
MCP_SERVER_URL=http://localhost:8000

# Database Configuration (if needed)
DATABASE_URL=your_database_url
# Database Configuration
# For SQLite local development (recommended for development)
DATABASE_TYPE=sqlite
DATABASE_URL=sqlite:///local_dev.db

# For production databases (uncomment and configure as needed)
# DATABASE_TYPE=sqlalchemy
# DATABASE_URL=postgresql://user:password@localhost:5432/dbname

# For Snowflake (uncomment and configure as needed)
# DATABASE_TYPE=snowflake
# SNOWFLAKE_ACCOUNT=your_account
# SNOWFLAKE_USER=your_user
# SNOWFLAKE_PASSWORD=your_password
# SNOWFLAKE_DATABASE=your_database
# SNOWFLAKE_SCHEMA=your_schema
# SNOWFLAKE_WAREHOUSE=your_warehouse

# Application Configuration
NODE_ENV=development
Expand Down
84 changes: 84 additions & 0 deletions scripts/init_sqlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python3
"""
SQLite Database Initialization Script

This script initializes a SQLite database for local development.
It creates the database file and sets up the basic schema structure.

Usage:
python scripts/init_sqlite.py

Requirements:
- SQLAlchemy
- Your SQLAlchemy models/base configuration

Environment Variables:
- DATABASE_URL: SQLite connection string (default: sqlite:///local_dev.db)
"""

import os
import sys
from sqlalchemy import create_engine, MetaData, text
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

# Import your SQLAlchemy models here
# from your_models import Base, YourModel1, YourModel2

# Database configuration
DATABASE_URL = os.getenv('DATABASE_URL', 'sqlite:///local_dev.db')

def init_database():
"""Initialize the SQLite database with schema."""
try:
print(f"Initializing SQLite database at: {DATABASE_URL}")

# Create engine
engine = create_engine(DATABASE_URL, echo=True)

# Create all tables defined in your models
# Replace this with your actual Base.metadata.create_all() call
# Base.metadata.create_all(engine)

print("✅ Database initialized successfully!")
print(f"📁 Database file location: {DATABASE_URL.replace('sqlite:///', '')}")

# Optional: Create a test connection
with engine.connect() as conn:
result = conn.execute(text("SELECT sqlite_version()"))
version = result.fetchone()[0]
print(f"📊 SQLite version: {version}")

except Exception as e:
print(f"❌ Error initializing database: {e}")
sys.exit(1)

def create_sample_data():
"""Optional: Create sample data for development."""
try:
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db = SessionLocal()

# Add your sample data creation logic here
# Example:
# sample_user = User(name="John Doe", email="[email protected]")
# db.add(sample_user)
# db.commit()

print("✅ Sample data created successfully!")

db.close()

except Exception as e:
print(f"❌ Error creating sample data: {e}")
sys.exit(1)

if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "--with-sample-data":
init_database()
create_sample_data()
else:
init_database()
print("\n💡 Tip: Run with --with-sample-data to also create sample data")
print(" python scripts/init_sqlite.py --with-sample-data")
Loading
Loading