Types
PgArray[T] = object dims*: seq[int32] lowerBounds*: seq[int32] elements*: seq[Option[T]]
-
N-dimensional PostgreSQL array value.
dims.len is the number of dimensions. dims.len == 0 represents an empty array (PostgreSQL ndim=0); otherwise elements holds the values in row-major (lexicographic) order with elements.len == product(dims). lowerBounds.len always equals dims.len; the default lower bound for each dimension is 1, matching PostgreSQL's default. NULL elements are represented as none(T).
Consts
PgArrayMaxDim = 6'i32
- Maximum number of array dimensions supported, matching PostgreSQL's MAXDIM (src/include/c.h). Both the encoder and the decoder reject arrays whose ndim exceeds this value.
Procs
proc expectedElemCount(dims: openArray[int32]): int {....raises: [PgTypeError], tags: [], forbids: [].}
- Compute the expected number of elements for an array with the given dimensions. By convention dims.len == 0 returns 0 (empty array marker); otherwise returns product(dims). Raises PgTypeError on any per-dim length <= 0 (PostgreSQL represents empty arrays with ndim == 0 rather than a zero-sized dimension), or when the product would exceed int32.high (PostgreSQL's wire format uses int32 for element counts). PgTypeError derives from PgError so existing except PgError callers keep working.
proc pgArray[T](dims, lowerBounds: openArray[int32]; elements: openArray[Option[T]]): PgArray[T]
- Construct an N-dimensional PgArray with explicit lowerBounds (one per dimension). elements must be in row-major order with elements.len == product(dims).
proc pgArray[T](dims: openArray[int32]; elements: openArray[Option[T]]): PgArray[ T]
- Construct an N-dimensional PgArray from elements that may be NULL. elements must be in row-major order with elements.len == product(dims). lowerBounds defaults to 1 for each dimension.
proc pgArray[T](dims: openArray[int32]; elements: openArray[T]): PgArray[T]
- Construct an N-dimensional PgArray from non-NULL elements. elements must be in row-major order with elements.len == product(dims). lowerBounds defaults to 1 for each dimension.
proc validatePgArrayShape(dims, lowerBounds: openArray[int32]; elementsLen: int) {. ...raises: [PgTypeError], tags: [], forbids: [].}
- Validate dims/lowerBounds/elements shape consistency for an N-dimensional array. Raises PgTypeError on mismatch, exceeded PgArrayMaxDim, element-count overflow, or any per-dim length <= 0 when dims.len > 0 (PostgreSQL represents empty arrays with ndim == 0 rather than a zero-sized dimension). PgTypeError derives from PgError so existing except PgError callers keep working.