gcharanteja commited on
Commit ·
ec417fa
1
Parent(s): 419fce7
README.md
CHANGED
|
@@ -1,156 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
✅ **Dual Services** - SQLite server (port 8000) + FastAPI wrapper (port 7860)
|
| 10 |
-
✅ **Schema Management** - Query schema and list tables
|
| 11 |
-
✅ **HF Spaces Ready** - Docker setup for Hugging Face deployment
|
| 12 |
-
|
| 13 |
-
## Architecture
|
| 14 |
-
|
| 15 |
-
```
|
| 16 |
-
┌─────────────────────────────────────────────┐
|
| 17 |
-
│ HF Spaces Container │
|
| 18 |
-
├─────────────────────────────────────────────┤
|
| 19 |
-
│ Port 7860 (exposed) │
|
| 20 |
-
│ ├── FastAPI Wrapper (app.py) │
|
| 21 |
-
│ │ └── Proxies to SQLite Server │
|
| 22 |
-
│ │ │
|
| 23 |
-
│ Port 8000 (internal) │
|
| 24 |
-
│ └── SQLite Server (sqlite_server.py) │
|
| 25 |
-
│ └── /data/sqlite.db (persistent) │
|
| 26 |
-
└─────────────────────────────────────────────┘
|
| 27 |
-
```
|
| 28 |
-
|
| 29 |
-
## API Endpoints
|
| 30 |
-
|
| 31 |
-
### Health Check
|
| 32 |
-
```bash
|
| 33 |
-
GET /health
|
| 34 |
-
GET /api/v1/heartbeat
|
| 35 |
-
```
|
| 36 |
-
|
| 37 |
-
### Query Data (SELECT)
|
| 38 |
-
```bash
|
| 39 |
-
POST /api/v1/query
|
| 40 |
-
Content-Type: application/json
|
| 41 |
-
|
| 42 |
-
{
|
| 43 |
-
"sql": "SELECT * FROM users"
|
| 44 |
-
}
|
| 45 |
-
```
|
| 46 |
-
|
| 47 |
-
### Execute (INSERT/UPDATE/DELETE)
|
| 48 |
-
```bash
|
| 49 |
-
POST /api/v1/execute
|
| 50 |
-
Content-Type: application/json
|
| 51 |
-
|
| 52 |
-
{
|
| 53 |
-
"sql": "INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')"
|
| 54 |
-
}
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
-
### Schema & Tables
|
| 58 |
-
```bash
|
| 59 |
-
GET /api/v1/tables
|
| 60 |
-
GET /api/v1/schema
|
| 61 |
-
```
|
| 62 |
-
|
| 63 |
-
## Deployment to HF Spaces
|
| 64 |
-
|
| 65 |
-
1. **Create a new Space:**
|
| 66 |
-
- Go to https://huggingface.co/new-space
|
| 67 |
-
- Select "Docker" as SDK
|
| 68 |
-
- Upload/push this repo
|
| 69 |
-
|
| 70 |
-
2. **Files needed:**
|
| 71 |
-
- `Dockerfile` - Container setup
|
| 72 |
-
- `start.sh` - Startup script
|
| 73 |
-
- `app.py` - FastAPI wrapper
|
| 74 |
-
- `sqlite_server.py` - SQLite API server
|
| 75 |
-
- `requirements.txt` - Python dependencies
|
| 76 |
-
|
| 77 |
-
3. **Persistent Storage:**
|
| 78 |
-
- HF Spaces automatically mounts `/data` as persistent volume
|
| 79 |
-
- SQLite database is stored at `/data/sqlite.db`
|
| 80 |
-
- Data persists across Space restarts
|
| 81 |
-
|
| 82 |
-
## Local Testing
|
| 83 |
-
|
| 84 |
-
```bash
|
| 85 |
-
# Install dependencies
|
| 86 |
-
npm install
|
| 87 |
-
pip install -r requirements.txt
|
| 88 |
-
|
| 89 |
-
# Start the servers
|
| 90 |
-
source venv/bin/activate
|
| 91 |
-
python3 sqlite_server.py & # Port 8000
|
| 92 |
-
python3 app.py & # Port 7860
|
| 93 |
-
|
| 94 |
-
# Run tests
|
| 95 |
-
npm run test
|
| 96 |
-
```
|
| 97 |
-
|
| 98 |
-
## File Structure
|
| 99 |
-
|
| 100 |
-
```
|
| 101 |
-
.
|
| 102 |
-
├── app.py # FastAPI wrapper (port 7860)
|
| 103 |
-
├── sqlite_server.py # SQLite API server (port 8000)
|
| 104 |
-
├── start.sh # Startup script
|
| 105 |
-
├── Dockerfile # Container configuration
|
| 106 |
-
├── requirements.txt # Python dependencies
|
| 107 |
-
├── package.json # Node.js test config
|
| 108 |
-
├── test.js # Test suite
|
| 109 |
-
└── README.md # This file
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
## Example Usage
|
| 113 |
-
|
| 114 |
-
### Create a table
|
| 115 |
-
```bash
|
| 116 |
-
curl -X POST https://your-space.hf.space/api/v1/execute \
|
| 117 |
-
-H "Content-Type: application/json" \
|
| 118 |
-
-d '{
|
| 119 |
-
"sql": "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)"
|
| 120 |
-
}'
|
| 121 |
-
```
|
| 122 |
-
|
| 123 |
-
### Insert data
|
| 124 |
-
```bash
|
| 125 |
-
curl -X POST https://your-space.hf.space/api/v1/execute \
|
| 126 |
-
-H "Content-Type: application/json" \
|
| 127 |
-
-d '{
|
| 128 |
-
"sql": "INSERT INTO users (name, email) VALUES ('"'"'Alice'"'"', '"'"'alice@example.com'"'"')"
|
| 129 |
-
}'
|
| 130 |
-
```
|
| 131 |
-
|
| 132 |
-
### Query data
|
| 133 |
-
```bash
|
| 134 |
-
curl -X POST https://your-space.hf.space/api/v1/query \
|
| 135 |
-
-H "Content-Type: application/json" \
|
| 136 |
-
-d '{"sql": "SELECT * FROM users"}'
|
| 137 |
-
```
|
| 138 |
-
|
| 139 |
-
## Troubleshooting
|
| 140 |
-
|
| 141 |
-
**Health check fails:**
|
| 142 |
-
- Ensure SQLite server started before FastAPI wrapper
|
| 143 |
-
- Check `start.sh` sleep duration (currently 2 seconds)
|
| 144 |
-
|
| 145 |
-
**Port conflicts:**
|
| 146 |
-
- SQLite server: port 8000 (internal)
|
| 147 |
-
- FastAPI wrapper: port 7860 (exposed on HF Spaces)
|
| 148 |
-
|
| 149 |
-
**Data not persisting:**
|
| 150 |
-
- Verify `/data` directory exists
|
| 151 |
-
- Check HF Spaces has persistent storage enabled
|
| 152 |
-
- Database file should be at `/data/sqlite.db`
|
| 153 |
-
|
| 154 |
-
## Credits
|
| 155 |
-
|
| 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