postgres-kit icon indicating copy to clipboard operation
postgres-kit copied to clipboard

Improve pool use documentation?

Open stephencelis opened this issue 5 years ago • 2 comments

The README currently shows how to get a database from a pool:

let postgres = pool.database(logger: ...) // PostgresDatabase
let rows = try postgres.simpleQuery("SELECT version();").wait()

Should you go through pool whenever you want to query? Or can you keep postgres around and use it for all of your queries?

stephencelis avatar Oct 06 '20 21:10 stephencelis

@gwynne is the best person to answer, however I think storing postgres (in a thread-safe way, e.g. on an event loop) should be fine

0xTim avatar Nov 02 '20 10:11 0xTim

In this context, the database connection stays open as long as postgres is alive (e.g. has at least one strong retain left on it). If it gets stored somewhere, you have to ensure you also eventually remove it from the storage; in particular, it must be released before the event loop that it runs on is shut down.

gwynne avatar Nov 02 '20 11:11 gwynne