Database
Functions
Grouped function reference for extension APIs and major database utilities
How to Read This Page
The package exports many functions and methods. This page groups the APIs you usually call in real app code, while keeping symbol names explicit for quick lookup.
Extension and Config APIs
Extension Construction and Lifecycle
NewExtension(opts ...ConfigOption) forge.ExtensionNewExtensionWithConfig(config Config) forge.Extension(*Extension).Register(app forge.App) error(*Extension).Start(ctx context.Context) error(*Extension).Stop(ctx context.Context) error(*Extension).Health(ctx context.Context) error
Config Helpers
DefaultConfig() Config(*Config).Validate() errorWithDatabases(databases ...DatabaseConfig) ConfigOptionWithDatabase(db DatabaseConfig) ConfigOptionWithDefault(name string) ConfigOptionWithRequireConfig(require bool) ConfigOptionWithConfig(config Config) ConfigOptionMaskDSN(dsn string, dbType DatabaseType) string
Manager and Database Access APIs
Manager
NewDatabaseManager(logger forge.Logger, metrics forge.Metrics) *DatabaseManager(*DatabaseManager).Register(name string, db Database) error(*DatabaseManager).RegisterAndOpen(ctx context.Context, name string, db Database) error(*DatabaseManager).Get(name string) (Database, error)(*DatabaseManager).SetDefault(name string) error(*DatabaseManager).Default() (Database, error)(*DatabaseManager).DefaultName() string(*DatabaseManager).SQL(name string) (*bun.DB, error)(*DatabaseManager).Mongo(name string) (*mongo.Client, error)(*DatabaseManager).MongoDatabase(name string) (*MongoDatabase, error)(*DatabaseManager).Redis(name string) (redis.UniversalClient, error)(*DatabaseManager).RedisDatabase(name string) (*RedisDatabase, error)(*DatabaseManager).OpenAll(ctx context.Context) error(*DatabaseManager).CloseAll(ctx context.Context) error(*DatabaseManager).HealthCheckAll(ctx context.Context) map[string]HealthStatus(*DatabaseManager).List() []string(*DatabaseManager).Health(ctx context.Context) error(*DatabaseManager).Start(ctx context.Context) error(*DatabaseManager).Stop(ctx context.Context) error
Container/App Helper Functions
Container:
GetManager,MustGetManagerGetDefault,MustGetDefaultGetDatabase,MustGetDatabaseGetSQL,MustGetSQLGetMongo,MustGetMongoGetRedis,MustGetRedisGetNamedDatabase,MustGetNamedDatabaseGetNamedSQL,MustGetNamedSQLGetNamedMongo,MustGetNamedMongoGetNamedRedis,MustGetNamedRedis
App wrappers:
GetManagerFromApp,MustGetManagerFromAppGetDatabaseFromApp,MustGetDatabaseFromAppGetSQLFromApp,MustGetSQLFromAppGetMongoFromApp,MustGetMongoFromAppGetRedisFromApp,MustGetRedisFromAppGetNamedDatabaseFromApp,MustGetNamedDatabaseFromAppGetNamedSQLFromApp,MustGetNamedSQLFromAppGetNamedMongoFromApp,MustGetNamedMongoFromAppGetNamedRedisFromApp,MustGetNamedRedisFromApp
Repository and tx wrappers:
NewRepositoryFromContainer[T]NewRepositoryFromApp[T]WithTransactionFromContainer(...)WithTransactionFromApp(...)
Driver Wrapper APIs
SQL Wrapper (SQLDatabase)
NewSQLDatabase(config, logger, metrics)Open,Close,PingIsOpen,State,Name,TypeDriver,DB,BunHealth,StatsTransaction,TransactionWithOptions
Mongo Wrapper (MongoDatabase)
NewMongoDatabase(config, logger, metrics)Open,Close,PingIsOpen,State,Name,TypeDriver,Client,Database,CollectionHealth,StatsTransaction,TransactionWithOptions
Redis Wrapper (RedisDatabase)
NewRedisDatabase(config, logger, metrics)Open,Close,PingIsOpen,State,Name,TypeDriver,ClientHealth,StatsPipeline,TxPipelineTransaction,Pipelined,TxPipelined
Data Access and Utility APIs
Repository Pattern
NewRepository[T](db IDB) *Repository[T](*Repository[T]).DB() IDB(*Repository[T]).Query() *bun.SelectQuery- CRUD and query methods:
FindByID,FindOne,FindAll,FindAllWithDeletedExists,CountCreate,CreateMany,Update,UpdateColumnsDelete,DeleteMany,SoftDelete,RestoreSoftDeleted,Truncate
Query options:
WithLimit,WithOffset,WithOrderWhereActive,WhereDeletedWithRelation,WithRelations
Bulk Operations
BulkInsertBulkInsertWithOptionsBulkUpdateBulkUpsertBulkDeleteBulkSoftDeleteBulkInsertWithProgressBulkUpdateWithProgressChunkSlice
Pagination
(*OffsetPagination).Normalize()(*OffsetPagination).Offset()Paginate[T](...)(*CursorPagination).Normalize()PaginateCursor[T](...)
Mapping Utilities
MapTo,MapSlice,MapPaginated,MapCursorMapPointer,MapSlicePointersMapError,MapSliceError,MapPaginatedError,MapCursorErrorFilterSlice,GroupBy,IndexBy,Pluck,Unique,Partition
Transactions and Context APIs
WithTransactionWithTransactionOptionsWithNestedTransactionGetDBMustGetDBIsInTransactionGetTransactionDepthGetTransactionStatsResetTransactionStatsWithSerializableTransactionWithReadOnlyTransactionWithRepeatableReadTransaction
Migration and Seeding APIs
Migrations
NewNoopMigrationLoggerNewMigrationManager(*MigrationManager).CreateTables(*MigrationManager).Migrate(*MigrationManager).Rollback(*MigrationManager).Status(*MigrationManager).Reset(*MigrationManager).AutoMigrate(*MigrationManager).CreateMigration
Seeders
NewSeederRunner(*SeederRunner).WithTracking(*SeederRunner).Register(*SeederRunner).RegisterMany(*SeederRunner).Run(*SeederRunner).RunSeeder(*SeederRunner).Reset(*SeederRunner).ResetAll(*SeederRunner).List
Observability APIs
ExplainQueryNewObservabilityQueryHook(*ObservabilityQueryHook).WithAutoExplainEnableAutoExplainFormatQueryPlan
Model Base Types and Context Helpers
Model helper methods are exported on base structs in models.go:
BeforeInsert,BeforeUpdate,BeforeDeleteIsDeleted,Restore
User context helpers:
SetXIDUserID,GetXIDUserIDSetUserID,GetUserID
Error APIs
NewDatabaseErrorErrNoDatabasesConfiguredErrInvalidDatabaseNameErrInvalidDatabaseTypeErrInvalidDSNErrInvalidPoolConfigErrDatabaseNotFoundErrDatabaseAlreadyExistsErrDatabaseNotOpenedErrInvalidDatabaseTypeOpErrConnectionFailedErrQueryFailedErrTransactionFailedErrPanicRecovered
Testing Helpers (Non-production)
NewTestDBWithInMemory,WithLogging,WithAutoMigrate,WithTransactionRollbackSeedFixtures,TruncateTables,CleanupDBAssertRecordExists,AssertRecordNotExists,AssertRecordCount,AssertRecordCountWhereLoadFixture,LoadAllFixtures
Source Navigation Tip
go doc github.com/xraph/forge/extensions/database/...Use this command when you need full symbol-level details while keeping this page as your architecture-first map.
How is this guide?