# `Bobbin.Connections`
[🔗](https://github.com/heddlehq/Bobbin/blob/main/lib/bobbin/connections.ex#L1)

Keeps the connection to a database open while runs use it.

A For Each that writes 1000 rows shouldn't log in 1000 times, and 1000 runs at once
shouldn't open 1000 connections. So each credential gets one supervised process,
which owns the driver's connection and closes it after a while without use. If the
driver dies this process goes with it, and the next run opens a new one.

Processes are found by a hash of the credential's values, so a changed password
gets a new connection and no secret ends up in a process name.

# `check`

Tries `connect` in a process of its own, and returns `:ok` or `{:error, message}`.

Drivers connect in the background and only log why they couldn't, and some kill or
trap exits in whoever calls them. This keeps the reason for the person who has to fix
the credential. What a driver raises can print its options, which hold the password,
so that never goes any further.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `start_link`

# `with_connection`

Calls `fun` with the connection for `values`, opening it with `connect` if needed.

`connect` returns `{:ok, pid}` or `{:ok, pid, connection}`, with `pid` linked to the
caller, or `{:error, message}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
