Database
Implementation-accurate guide for Forge database extension
Overview
github.com/xraph/forge/extensions/database provides a unified extension for:
- SQL databases via Bun (
postgres,mysql,sqlite) - MongoDB
- Redis (standalone, cluster, sentinel)
The extension registers a DatabaseManager and database accessors in the container, then coordinates connection lifecycle.
What This Extension Handles
- Config loading from app config (
extensions.databasethendatabase) plus programmatic options - Database object creation by
DatabaseType - Eager registration/opening of configured databases through
DatabaseManager - Default database selection
- Typed helper access for SQL, Mongo, and Redis
Runtime Model
DatabaseManageris the central registry for named databases.- Database connections are opened with retry and backoff logic.
- Health checks and metrics are emitted per database.
DatabaseManagerimplements service lifecycle methods (Start,Stop,Health).
Read This Next
Getting Started
Create a working setup quickly with typed injection and named database access.
Features
Complete feature map including pooling, retries, observability, and helper layers.
Configuration
Config schema, defaults, validation behavior, and config merge precedence.
Lifecycle and DI
How manager and accessors are registered and resolved through Vessel.
Drivers
SQL, MongoDB, and Redis backend behavior and DSN patterns.
Repository and Pagination
Generic repository usage, query options, and offset/cursor pagination.
Transactions
Nested transactions with savepoints and transaction-aware DB resolution.
Migrations and Seeding
Migration manager and idempotent seed orchestration.
Testing
In-memory test DB helpers and fixture assertions.
Functions
Grouped function reference for extension, manager, helpers, and data APIs.
Troubleshooting
Fix common startup, typing, and transaction issues.
How is this guide?