Skip to content

rskworld/sql-database-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SQL Database Manager

A comprehensive database management system with SQL and multiple database support.

SQL Database Manager License Python FastAPI

πŸš€ Features

πŸ—„οΈ Database Management

  • Multiple Database Support: MySQL, PostgreSQL, SQLite
  • Real-time Query Execution: Run SQL queries with live results
  • Database Schema Inspection: View tables, columns, and relationships
  • Connection Management: Easy database connection setup

πŸ”§ Query Tools

  • SQL Editor: Write and execute custom SQL queries
  • Query Builder: Visual query construction interface
  • Query History: Track and reuse previous queries
  • Syntax Highlighting: Enhanced SQL code editing

πŸ“Š Data Operations

  • Data Import: CSV and JSON file import with automatic table creation
  • Data Export: Export query results to CSV/JSON formats
  • Data Visualization: Charts and graphs with Chart.js
  • Bulk Operations: Handle large datasets efficiently

πŸ‘₯ User Management

  • Secure Authentication: JWT-based login system
  • User Registration: Multi-user support with role management
  • Session Management: Secure token-based sessions
  • Password Security: Bcrypt password hashing

🎨 User Interface

  • Modern Design: Clean, responsive interface
  • Dark/Light Theme: Multiple theme options
  • Mobile Responsive: Works on all devices
  • Real-time Updates: Live data refresh

πŸ› οΈ Technologies

Backend

  • FastAPI: Modern, fast web framework for APIs
  • SQLite: Default database for user management
  • PyMySQL: MySQL database connector
  • psycopg2: PostgreSQL database connector
  • JWT: JSON Web Tokens for authentication
  • bcrypt: Password hashing
  • pandas: Data manipulation and analysis

Frontend

  • HTML5: Semantic markup
  • CSS3: Modern styling with animations
  • JavaScript (ES6+): Modern JavaScript features
  • Chart.js: Data visualization library
  • Font Awesome: Icon library
  • Responsive Design: Mobile-first approach

Database Support

  • SQLite: Lightweight, file-based database
  • MySQL: Popular relational database
  • PostgreSQL: Advanced open-source database

πŸ“‹ Prerequisites

  • Python 3.8+: Backend runtime environment
  • pip: Python package manager
  • Modern Web Browser: Chrome, Firefox, Safari, or Edge
  • Internet Connection: For package installation

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/rskworld/sql-database-manager.git
cd sql-database-manager

2. Backend Setup

# Navigate to backend directory
cd backend

# Install Python dependencies
pip install -r requirements.txt

# Start the FastAPI server
uvicorn main:app --reload

# The backend will be available at http://localhost:8000

3. Frontend Setup

# Navigate to frontend directory
cd frontend

# No build process required - just open the HTML file
# Option 1: Double-click index.html
# Option 2: Use a live server for better development

4. Access the Application

πŸ” Default Credentials

  • Username: admin
  • Password: admin123

πŸ“– Detailed Usage Guide

Database Connection

  1. Select Database Type: Choose from SQLite, MySQL, or PostgreSQL
  2. Configure Connection: Enter connection details
  3. Test Connection: Verify database connectivity
  4. Save Connection: Store connection for later use

Query Execution

  1. Write SQL Query: Use the SQL editor or query builder
  2. Execute Query: Click "Run Query" to execute
  3. View Results: Results display in a formatted table
  4. Export Results: Save results to CSV or JSON

Data Import/Export

Import Data

  1. Select File: Choose CSV or JSON file
  2. Configure Import: Set table name and options
  3. Import Data: Automatic table creation and data insertion
  4. Verify Import: Check imported data quality

Export Data

  1. Select Data: Choose table or write query
  2. Choose Format: CSV or JSON export
  3. Export Data: Download file with results
  4. Verify Export: Check exported file integrity

Data Visualization

  1. Select Data Source: Table or custom query
  2. Choose Chart Type: Bar, line, pie, or scatter chart
  3. Configure Chart: Set labels, colors, and options
  4. Generate Chart: Interactive visualization

πŸ—οΈ Project Structure

sql-database-manager/
β”œβ”€β”€ backend/                 # FastAPI backend
β”‚   β”œβ”€β”€ main.py             # Main application file
β”‚   β”œβ”€β”€ auth.py             # Authentication logic
β”‚   β”œβ”€β”€ database.py         # Database operations
β”‚   β”œβ”€β”€ models.py           # Pydantic models
β”‚   β”œβ”€β”€ query_builder.py    # SQL query builder
β”‚   β”œβ”€β”€ data_io.py          # Data import/export
β”‚   β”œβ”€β”€ users.py            # User management
β”‚   β”œβ”€β”€ config.py           # Configuration
β”‚   β”œβ”€β”€ utils.py            # Utility functions
β”‚   └── requirements.txt    # Python dependencies
β”œβ”€β”€ frontend/               # Web frontend
β”‚   β”œβ”€β”€ index.html          # Main application page
β”‚   β”œβ”€β”€ login.html          # User login page
β”‚   β”œβ”€β”€ register.html       # User registration page
β”‚   β”œβ”€β”€ style.css           # Application styles
β”‚   β”œβ”€β”€ script.js           # Main JavaScript logic
β”‚   β”œβ”€β”€ auth.js             # Authentication handling
β”‚   β”œβ”€β”€ query_builder.js    # Query builder interface
β”‚   β”œβ”€β”€ data_io.js          # Data import/export UI
β”‚   └── visualization.js    # Chart generation
β”œβ”€β”€ assets/                 # Static assets
β”œβ”€β”€ docs/                   # Documentation
β”œβ”€β”€ LICENSE                 # License file
└── README.md               # This file

πŸ”§ Configuration

Backend Configuration

Edit backend/config.py to modify database connections:

DB_CONFIGS = {
    "mysql": {
        "host": "localhost",
        "port": 3306,
        "user": "root",
        "password": "",
    },
    "postgresql": {
        "host": "localhost",
        "port": 5432,
        "user": "postgres",
        "password": "",
    },
    "sqlite": {
        "db_path": "mydatabase.db"
    }
}

Frontend Configuration

Modify frontend/script.js to change API endpoints:

const API_BASE_URL = 'http://localhost:8000';

πŸ§ͺ Testing

Backend Tests

# Test API endpoints
curl http://localhost:8000/test

# Test authentication
curl -X POST "http://localhost:8000/token" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "username=admin&password=admin123"

# Test query execution
curl -X POST "http://localhost:8000/query" \
     -H "Authorization: Bearer YOUR_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"query":"SELECT 1","db_type":"sqlite","db_config":{}}'

Frontend Tests

  • Open browser developer tools
  • Test all UI components
  • Verify API calls in network tab
  • Check console for errors

πŸš€ Deployment

Development Deployment

# Backend
uvicorn main:app --host 0.0.0.0 --port 8000

# Frontend (serve with any web server)
python -m http.server 3000 --directory frontend

Production Deployment

# Backend with Gunicorn
pip install gunicorn
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app

# Frontend with Nginx (configure nginx to serve frontend files)

Docker Deployment

# Dockerfile
FROM python:3.9-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ API Documentation

Authentication Endpoints

  • POST /token - Get access token
  • POST /users/ - Register new user
  • GET /users/me/ - Get current user info

Database Endpoints

  • POST /connect - Test database connection
  • GET /schema/{db_type} - Get database schema
  • POST /query - Execute SQL query
  • POST /build-query - Build SQL query

Data Endpoints

  • POST /import-data - Import data from file
  • POST /export-data - Export data to file
  • POST /create-sample-data - Create sample database

πŸ› Troubleshooting

Common Issues

Backend Issues

  • Port 8000 in use: Change port with --port 8001
  • Module not found: Run pip install -r requirements.txt
  • Database connection failed: Check database credentials

Frontend Issues

  • CORS errors: Backend CORS configuration
  • API calls failing: Check backend is running
  • Authentication errors: Verify login credentials

Database Issues

  • SQLite file not found: Check file permissions
  • MySQL connection failed: Verify MySQL service
  • PostgreSQL connection failed: Check PostgreSQL service

Debug Mode

Enable debug logging:

# In main.py
import logging
logging.basicConfig(level=logging.DEBUG)

πŸ“Š Performance

Query Performance

  • Use indexes for large tables
  • Limit result sets with pagination
  • Optimize SQL queries

Application Performance

  • Enable connection pooling
  • Use caching for frequent queries
  • Optimize frontend JavaScript

πŸ”’ Security

Authentication Security

  • JWT tokens with expiration
  • Secure password hashing
  • CORS protection
  • SQL injection prevention

Data Security

  • Input validation
  • Parameterized queries
  • Secure file uploads
  • Rate limiting

πŸ“ˆ Roadmap

Version 1.1 (Planned)

  • Advanced query builder
  • Database migration tools
  • Query optimization suggestions
  • Dark theme support

Version 1.2 (Future)

  • Multi-database transactions
  • Advanced data visualization
  • Query scheduling
  • API rate limiting

πŸ“ž Support

Contact Information

Documentation

πŸ™ Acknowledgments

  • FastAPI: For the excellent web framework
  • Chart.js: For data visualization capabilities
  • Font Awesome: For beautiful icons
  • Open Source Community: For inspiration and contributions

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


⭐ If this project helped you, please give it a star!

πŸ› Found a bug? Please report it on GitHub Issues

πŸ’‘ Have a suggestion? Please open an Issue

About

Build a comprehensive database management system supporting multiple SQL databases. Features query builder, data import/export, user management, and visualization tools. Perfect for learning SQL, database design, and data management principles.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors