# postgres.params

> A module of postgres's API.

`postgres.params` — the `Params` builder for `PQexecParams` / `PQexecPrepared`.

Collects `$1`-style query parameters, always in text format (this tin never
sends binary-format parameters). `Params` keeps three parallel lists —
values, null flags, and OIDs — that the FFI layer reads by index when it
builds the `char* const*`/`Oid*`/`int*` arrays libpq wants.

Every typed builder method encodes through `postgres.text` and is chainable
by consuming and returning `self`, so a call reads like::

    var p = Params().text("gold").int64(7).timestamptz_micros(now)

`.text()` binds OID 0 — the server infers the parameter's type from query
context, which is what you want for an untyped literal. Use `.typed()` as an
escape hatch for a value/OID pair this module has no dedicated method for.

## Structs

### `Params`

```mojo
struct Params
```

A builder for one query's parameter list.

`Params()` starts empty. Each builder method appends one parameter and
returns `self` so calls chain; `__len__`, `value(i)`, `is_null(i)`, and
`oid(i)` are the read side the FFI layer uses to fill libpq's parameter
arrays.

Implements: `Copyable`, `Movable`, `Sized`

#### `__init__`

```mojo
def __init__(out self)
```

#### `__len__`

```mojo
def __len__(self) -> Int
```

Number of parameters bound so far.

#### `value`

```mojo
def value(self, i: Int) -> String
```

The text form of parameter `i` (0-based). Meaningless — and conventionally the empty string — when `is_null(i)` is `True`.

#### `is_null`

```mojo
def is_null(self, i: Int) -> Bool
```

Whether parameter `i` is SQL NULL.

#### `oid`

```mojo
def oid(self, i: Int) -> UInt32
```

The OID parameter `i` was bound with; `0` lets the server infer the type from query context.

#### `text`

```mojo
def text(var self, v: String) -> Self
```

Bind `v` untyped (OID 0) — the server infers the type from context.

#### `int16`

```mojo
def int16(var self, v: Int16) -> Self
```

#### `int32`

```mojo
def int32(var self, v: Int32) -> Self
```

#### `int64`

```mojo
def int64(var self, v: Int64) -> Self
```

#### `float32`

```mojo
def float32(var self, v: Float32) -> Self
```

#### `float64`

```mojo
def float64(var self, v: Float64) -> Self
```

#### `bool`

```mojo
def bool(var self, v: Bool) -> Self
```

#### `numeric`

```mojo
def numeric(var self, v: String) -> Self
```

Bind an already-formatted `numeric` literal. Kept a `String` — see `postgres.text`'s module docstring for why.

#### `bytea`

```mojo
def bytea(var self, v: Span[UInt8]) -> Self
```

#### `date_days`

```mojo
def date_days(var self, v: Int32) -> Self
```

`v` is days since 1970-01-01, as returned by `text.decode_date`.

#### `time_micros`

```mojo
def time_micros(var self, v: Int64) -> Self
```

`v` is microseconds since midnight, as returned by `text.decode_time`.

#### `timestamp_micros`

```mojo
def timestamp_micros(var self, v: Int64) -> Self
```

`v` is microseconds since 1970-01-01 00:00:00 (naive, no zone), as returned by `text.decode_timestamp`.

#### `timestamptz_micros`

```mojo
def timestamptz_micros(var self, v: Int64) -> Self
```

`v` is UTC microseconds since 1970-01-01 00:00:00, as returned by `text.decode_timestamptz`.

#### `uuid`

```mojo
def uuid(var self, v: String) -> Self
```

#### `json`

```mojo
def json(var self, v: String) -> Self
```

#### `jsonb`

```mojo
def jsonb(var self, v: String) -> Self
```

#### `null`

```mojo
def null(var self, oid: UInt32 = UInt32(0)) -> Self
```

Bind SQL NULL, optionally typed with `oid` (default 0, server infers).

#### `typed`

```mojo
def typed(var self, value: String, oid: UInt32) -> Self
```

Escape hatch: bind an already-formatted text value with an explicit OID this module has no dedicated method for.
