-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Hi sqlgen developers,
Thanks very much for a great library. This is a summary of a problem I faced whilst developing with Claude code. When I get a moment I will have a go at implementing this feature, but if you have any feedback it would be appreciated.
Cheers
AI Generated summary starts here (with minor massaging by me).
Problem
PostgreSQL NOTICE messages (from RAISE NOTICE in PL/pgSQL functions) go directly to stderr via libpq's default notice processor. Applications using sqlgen cannot capture or redirect these messages to their own logging infrastructure.
Technical Details
- libpq provides
PQsetNoticeProcessor(PGconn*, callback, void*)to customize notice handling - sqlgen's
PostgresV2ConnectionwrapsPGconn*but doesn't set a notice processor - sqlgen's
ConnectionPoolcreates connections upfront but doesn't expose them - sqlgen's
Sessionholds the connection privately with no accessor
Current sqlgen Architecture:
ConnectionPool<Connection>
└── vector<pair<Ref<Connection>, atomic_flag>>
└── postgres::Connection
└── PostgresV2Connection
└── PGconn* (accessible via ptr())
Proposed Solution
Add an optional notice callback to ConnectionPoolConfig or postgres::Credentials:
- Option 1: Callback in pool config:
struct ConnectionPoolConfig {
size_t size = 4;
size_t num_attempts = 10;
size_t wait_time_in_seconds = 1;
std::function<void(const char*)> notice_handler; // NEW
};- Option 2: Callback in
postgres::CredentialsorConnectionconstructor:
In PostgresV2Connection::make(), after PQconnectdb(), call:
if (notice_handler) {
PQsetNoticeProcessor(conn, [](void* arg, const char* msg) {
auto* handler = static_cast<std::function<void(const char*)>*>(arg);
(*handler)(msg);
}, ¬ice_handler);
}Use Case
ORE Studio [1] test infrastructure provisions/deprovisions tenants using PostgreSQL functions that emit NOTICE messages. We want to capture these in boost::log instead of stderr.