database: create shared database package
Extract common database functionality from api/ntpdb and monitor/ntpdb into shared common/database package: - Dynamic connector pattern with configuration loading - Configurable connection pool management (API: 25/10, Monitor: 10/5) - Optional Prometheus metrics integration - Generic transaction helpers with proper error handling - Unified interfaces compatible with SQLC-generated code Foundation for migration to eliminate ~200 lines of duplicate code.
This commit is contained in:
@@ -41,11 +41,12 @@ func WithTransaction[Q TX](ctx context.Context, db DB[Q], fn func(ctx context.Co
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
err = tx.Commit(ctx)
|
||||
committed = true // Mark as committed regardless of commit success/failure
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to commit transaction: %w", err)
|
||||
}
|
||||
|
||||
committed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user