Overview
The Drizzle integration provides Effect-first database operations with automatic error handling and built-in transaction support. Create a Drizzle client wrapper once and use it throughout your application with full type safety.Installation
@libsql/client, postgres, @electric-sql/pglite).
Exports
createDrizzle
Create an Effect-based Drizzle client wrapper.Signature
Parameters
Effect.Effect<TClient, E, R>
required
An Effect that yields a Drizzle client instance. This can include any setup logic, connection pooling, etc.
string
Optional custom tag identifier. Useful when working with multiple databases. Defaults to
'@ff-effect/Drizzle'.Returns
Returns an object with:function
Execute database operations using the main client or transaction client (if inside
withTransaction).function
Execute operations that require being inside a transaction. Type-safe - only works within
withTransaction.Context.Tag
Context tag for the database client. Use this to access the raw client if needed.
Context.Tag
Context tag for transaction clients. Only available inside
withTransaction.function
Execute an Effect within a database transaction. Automatically rolls back on errors.
Layer
Layer that provides the database client to Effects.
Basic Usage
Setup
Simple Queries
Transactions
UsewithTransaction to execute multiple operations atomically.
Basic Transaction
Automatic Rollback
Transactions automatically roll back on errors:Transaction-Only Operations with tx
Use tx for operations that must run inside a transaction (enforced at compile-time):
Multiple Databases
Use customtagId to work with multiple databases:
Error Handling
DrizzleError
All database operations can fail withDrizzleError:
Transaction Errors
Transaction errors preserve the original error type:Real-World Example
Type Exports
The integration exports various Effect internal type IDs to avoid TypeScript declaration file generation issues. You don’t need to use these directly.
See Also
- Drizzle ORM Documentation
- extract - Used internally for transaction support
- Examples - More complex usage patterns