How are people managing external DB connections in DO's... specifically, I'm really struggling to fi

How are people managing external DB connections in DO's... specifically, I'm really struggling to find a clean pattern of when/where to close db connections (for ex to Postgres)
Initially I thought I'd just get away with connecting at the start of a request/rpc, and disconnecting at the end. But this can get pretty messy (if there are a lot of early returns / throws, your code gets peppered with disconnect calls. Sure you can wrap in a parent fn, but still feels ugly).
Ideally I could use a pool, keep it open to serve multiple (possibly concurrent) requests, but I have no idea when to close it. This is where an eviction/hibernation hook would come in handy.

Anyone have any good patterns here?
Was this page helpful?