effect/unstable/sql module. These packages offer type-safe, composable database clients for various SQL databases with built-in connection pooling, migrations, and reactive queries.
Core Features
All SQL packages share a common foundation:- Type-safe queries: Full TypeScript support with compile-time checking
- Connection pooling: Automatic connection management
- Transactions: Nested transaction support with savepoints
- Migrations: Built-in migration system
- Reactive queries: Automatic query invalidation and re-execution
- Error handling: Structured error types
- Effect integration: Seamless integration with Effect ecosystem
Available Databases
PostgreSQL
The@effect/sql-pg package provides PostgreSQL support using the pg library:
- Full PostgreSQL feature support
- LISTEN/NOTIFY support
- JSON/JSONB handling
- Cursor-based streaming
MySQL
The@effect/sql-mysql2 package provides MySQL support using the mysql2 library:
- MySQL 5.7+ and MariaDB support
- Prepared statements
- Connection pooling
- Full transaction support
SQLite
Multiple SQLite packages for different runtimes:@effect/sql-sqlite-node- Node.js using better-sqlite3@effect/sql-sqlite-bun- Bun’s native SQLite@effect/sql-sqlite-wasm- WebAssembly SQLite for browsers
Microsoft SQL Server
The@effect/sql-mssql package provides SQL Server support using the tedious library:
- SQL Server 2012+ support
- Stored procedures
- TVP (Table-Valued Parameters)
- Bulk operations
ClickHouse
The@effect/sql-clickhouse package provides ClickHouse support:
- High-performance analytics queries
- Column-oriented storage
- Real-time data ingestion
Common Usage Patterns
Basic Query
All SQL clients share a common query interface:Transactions
Transactions work consistently across all databases:Migrations
All packages include a migration system:Reactive Queries
Enable reactive queries that automatically re-execute when data changes:Connection Configuration
Each database has its own configuration options, but they follow similar patterns:Schema Generation
Generate TypeScript types from your database schema:Error Handling
All SQL operations return structured errors:Choosing a Database
| Database | Use Case | Key Features |
|---|---|---|
| PostgreSQL | General purpose, complex queries | Advanced features, JSONB, full-text search |
| MySQL | Web applications, WordPress | Wide hosting support, good performance |
| SQLite | Local/embedded, mobile apps | Serverless, single file, zero config |
| SQL Server | Enterprise, .NET integration | Enterprise features, stored procedures |
| ClickHouse | Analytics, time series | Column-oriented, high performance |