A experimental REST API for managing multiple SQLite databases with extension support, caching, query optimization, and SQL dialect conversion.
- Multi-Database Support: Create and manage multiple SQLite databases
- SQLite Extension Management: Load and use SQLite extensions
- Query Cache: LRU caching with configurable TTL for query results
- Asynchronous Execution: Non-blocking query execution with background processing
- Query Optimization: SQL query optimization using SQLGlot
- SQL Dialect Conversion: Convert between different SQL dialects
- Authentication: API key-based security
- Python 3.8+
- pip
- Clone the repository:
git clone https://github.com/joaojkuligowski/sqlite-multi-db-api.git
cd sqlite-multi-db-api- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create an
.envfile based on.env.example:
cp .env.example .env- Edit the
.envfile to set your API key and other configuration options.
python src/main.pyThis will start the server on http://localhost:8000.
POST /query- Execute a SQL queryGET /query/{query_id}- Get status and results of a query
POST /db/{db_name}- Create a new database
GET /extensions- List available extensionsPOST /extensions/load- Load an extension into a databaseGET /extensions/{extension_name}- Get information about an extensionGET /db/{db_name}/extensions- List extensions loaded in a database
POST /tools/optimize- Optimize a SQL queryPOST /tools/convert- Convert a query between SQL dialects
curl -X POST "http://localhost:8000/query" \
-H "X-API-Key: your-secret-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "SELECT * FROM example LIMIT 10",
"db_name": "default",
"cache_ttl": 300
}'curl -X POST "http://localhost:8000/db/my_new_db" \
-H "X-API-Key: your-secret-api-key"curl -X POST "http://localhost:8000/extensions/load" \
-H "X-API-Key: your-secret-api-key" \
-H "Content-Type: application/json" \
-d '{
"extension_name": "my_extension.so",
"db_name": "default"
}'curl -X POST "http://localhost:8000/tools/optimize" \
-H "X-API-Key: your-secret-api-key" \
-H "Content-Type: application/json" \
-d '{
"query": "SELECT a.id, b.name FROM table_a a LEFT JOIN table_b b ON a.id = b.id WHERE a.value > 10"
}'curl -X POST "http://localhost:8000/tools/convert" \
-H "X-API-Key: your-secret-api-key" \
-H "Content-Type: application/json" \
-d '{
"origin_dialect": "sqlite",
"target_dialect": "mysql",
"query": "SELECT * FROM users WHERE rowid = 1"
}'Edit the configuration in src/config.py or override using environment variables:
API_KEY: Authentication key for API accessDB_DIR: Directory to store SQLite databasesEXTENSIONS_DIR: Directory for SQLite extensionsMAX_WORKERS: Maximum number of worker threadsCACHE_EXPIRY: Default cache expiration time in secondsMAX_CACHE_SIZE: Maximum number of items in the query cache
To use SQLite extensions:
- Place your
.so(Linux),.dll(Windows), or.dylib(macOS) extension files in theextensions/directory - Load extensions using the API endpoints
pytest tests/- Create new models in the
src/models/directory - Implement service logic in the
src/services/directory - Add new endpoints in the
src/api/routes/directory - Register the endpoints in
src/api/router.py
MIT