# postgres.config

> A module of postgres's API.

Typed connection configuration.

`ConnectionConfig` is a small builder that emits a libpq conninfo string on
demand. Field names match libpq's documented keyword/value parameters (see
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS),
with underscores only where Mojo requires them.

`Connection` (elsewhere in this package) also accepts a URI directly —
`postgresql://user:pass@host:port/dbname?sslmode=require` — since libpq
parses both a conninfo string and a URI through the same entry point. This
builder exists for callers who would rather set typed fields than assemble a
URI by hand.

## Structs

### `ConnectionConfig`

```mojo
struct ConnectionConfig
```

Connection parameters for a libpq connection.

Build a `Connection` from this directly, or call `to_conninfo()` if you
want the raw libpq conninfo string for debugging or logging.

Implements: `Copyable`, `Movable`

Fields:

- `host: String`
- `port: Int`
- `dbname: String`
- `user: String`
- `password: String`
- `application_name: String`
- `sslmode: String`
- `connect_timeout: Int`

#### `__init__`

```mojo
def __init__(out self, host: String = "localhost", port: Int = Int(5432), dbname: String = "", user: String = "", password: String = "", application_name: String = "postgres.mojo", sslmode: String = "prefer", connect_timeout: Int = Int(10))
```

#### `set`

```mojo
def set(mut self, key: String, value: String)
```

Escape hatch for any libpq conninfo keyword not exposed as a typed field above (e.g. `target_session_attrs`, `options`).

Setting a key that was already set — by an earlier `set()` call —
replaces its value in place rather than adding a duplicate, so
`to_conninfo()` stays deterministic and each keyword appears at
most once.

#### `to_conninfo`

```mojo
def to_conninfo(self) -> String
```

Render to a libpq conninfo string (`key=value key=value ...`).

Extra keys set via `set()` are emitted last, in the order they were
first set.
