Skip to content

WorkerSQL

WorkerSQL Logo

MySQL-compatible edge database platform built on Cloudflare Workers

License Node.js Version TypeScript Cloudflare Workers

FeaturesQuick StartAPI ReferenceDocumentationContributing

WorkerSQL is a high-performance, MySQL-compatible edge database platform that brings your data closer to your users. Built on Cloudflare Workers, it provides:

  • Edge-native architecture with sub-50ms query latency globally
  • MySQL compatibility for seamless migration from existing applications
  • Automatic scaling with zero cold starts
  • Multi-tenant isolation with built-in security
  • Real-time caching with cache-aside pattern implementation
  • ACID transactions via Durable Objects
  • Sub-50ms latency globally via Cloudflare’s edge network
  • Intelligent caching with configurable TTL and stale-while-revalidate
  • Connection pooling and query optimization
  • Automatic shard management based on data size and access patterns
  • JWT-based authentication with role-based access control (RBAC)
  • Tenant isolation ensuring complete data separation
  • SQL injection prevention with parameterized queries
  • Encryption at rest and in transit using industry standards
  • Audit logging for compliance and monitoring
  • MySQL-compatible SQL - use existing tools and knowledge
  • RESTful API with comprehensive OpenAPI specification
  • WebSocket support for real-time updates
  • Multi-language SDKs (JavaScript/TypeScript, Python, PHP)
  • Local development tools with Miniflare integration
  • Real-time metrics and performance monitoring
  • Health checks and status endpoints
  • Detailed logging with configurable levels
  • Integration ready for external monitoring tools
  • Node.js 18+ and npm
  • Cloudflare account with Workers enabled
  • Wrangler CLI installed globally
Terminal window
# Clone the repository
git clone https://github.com/healthfees-org/workersql.git
cd workersql
# Install dependencies
npm install
# Set up development environment
npm run setup:dev
# Start local development server
npm run dev
Terminal window
# Test the health endpoint
curl http://localhost:8787/health
# Execute a SQL query
curl -X POST http://localhost:8787/v1/query \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"sql": "SELECT * FROM users WHERE active = ?",
"params": [true]
}'

All API requests require a valid JWT token:

Authorization: Bearer <jwt_token>
MethodEndpointDescription
POST/v1/queryExecute SQL query
POST/v1/query/batchExecute multiple queries
POST/v1/transactionsBegin transaction
POST/v1/transactions/{id}/commitCommit transaction
POST/v1/transactions/{id}/rollbackRollback transaction
GET/v1/schemaGet database schema
GET/v1/healthHealth check
GET/v1/metricsPerformance metrics
{
"sql": "SELECT * FROM products WHERE price > ? AND category = ?",
"params": [100, "electronics"],
"hints": {
"consistency": "strong",
"cacheTtl": 300000,
"shardKey": "tenant_123"
}
}
{
"success": true,
"data": {
"rows": [...],
"rowsAffected": 1,
"insertId": 123,
"metadata": {
"fromCache": false,
"shardId": "shard_0",
"executionTimeMs": 15
}
}
}
import { WorkerSQL } from '@workersql/client';
const db = new WorkerSQL({
apiKey: 'your-api-key',
baseUrl: 'https://api.workersql.com',
});
const users = await db.query('SELECT * FROM users WHERE id = ?', [123]);
from workersql import Client
db = Client(api_key='your-api-key')
result = db.query('SELECT * FROM users WHERE id = %s', [123])
<?php
use WorkerSQL\Client;
$db = new Client(['api_key' => 'your-api-key']);
$result = $db->query('SELECT * FROM users WHERE id = ?', [123]);

WorkerSQL is built on a distributed architecture optimized for edge computing:

┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Client SDK │────│ Edge Gateway │────│ Durable Object │
│ │ │ (Workers) │ │ Shards │
└─────────────────┘ └─────────────────┘ └─────────────────┘
┌─────────────────┐
│ KV Cache │
│ & Queues │
└─────────────────┘
  • Edge Gateway: Request routing, authentication, and caching
  • Durable Object Shards: ACID-compliant data storage
  • KV Cache: High-performance query result caching
  • Event Queues: Asynchronous operations and cache invalidation
  • Connection Manager: Efficient connection pooling and management
Terminal window
# Install dependencies
npm install
# Set up pre-commit hooks
npm run prepare
# Configure Wrangler
cp wrangler.toml.template wrangler.toml
wrangler auth login
# Create Cloudflare resources
npm run setup:cloudflare
Terminal window
# Run all tests
npm test
# Run specific test suites
npm run test:unit
npm run test:integration
npm run test:e2e
# Run tests with coverage
npm run test:coverage
# Watch mode for development
npm run test:watch
Terminal window
# Lint code
npm run lint
# Format code
npm run format
# Type checking
npm run type-check
# Complete quality check
npm run workflow:check
Terminal window
# Start development server with hot reload
npm run dev
# Build for production
npm run build
# Deploy to staging
npm run deploy:staging
  1. Development: Local testing with Miniflare
  2. Staging: Pre-production testing environment
  3. Production: Live production deployment
Terminal window
# Deploy to staging
wrangler deploy --env staging
# Deploy to production
wrangler deploy --env production
# View deployment logs
wrangler tail --env production
VariableDescriptionDefault
ENVIRONMENTDeployment environmentdevelopment
LOG_LEVELLogging verbosityinfo
MAX_SHARD_SIZE_GBMaximum shard size10
CACHE_TTL_MSCache TTL in milliseconds300000
JWT_SECRETJWT signing secret(required)
  • Query Latency: <50ms globally (p95)
  • Throughput: 10,000+ queries/second per edge location
  • Cache Hit Rate: 85%+ for typical workloads
  • Cold Start: 0ms (edge-native architecture)
  1. Use appropriate cache TTL for your data freshness requirements
  2. Optimize shard keys for even data distribution
  3. Batch related queries to reduce round trips
  4. Use read replicas for analytics workloads

We welcome contributions! Please see our Contributing Guidelines for details.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Run npm run workflow:check
  5. Submit a pull request

This project follows the Contributor Covenant Code of Conduct.

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

For enterprise support, SLA guarantees, and custom development:

  • ✅ Core SQL compatibility
  • ✅ Authentication & authorization
  • ✅ Multi-tenant isolation
  • ✅ Real-time caching
  • 🔄 Advanced analytics queries
  • 🔄 Cross-region replication
  • 🔄 GraphQL API support
  • 🔄 Enhanced monitoring dashboard
  • 📋 Full-text search capabilities
  • 📋 Advanced encryption features
  • 📋 Machine learning integrations

Made with ❤️ by the HealthFees team

WebsiteBlogTwitter