PostgresNIO Documentation

Protocol Postgres​Decodable

public protocol PostgresDecodable  

A type that can decode itself from a postgres wire binary representation.

If you want to conform a type to PostgresDecodable you must implement the decode method.

%331 PostgresDecodable PostgresDecodable PostgresArrayDecodable PostgresArrayDecodable PostgresArrayDecodable->PostgresDecodable PostgresCodable PostgresCodable PostgresCodable->PostgresDecodable

Types Conforming to Postgres​Decodable

PostgresArrayDecodable

A type that can be decoded into a Swift Array of its own type from a Postgres array.

Default Implementations

_decode​Raw(from:​type:​format:​context:​)

@inlinable
    public static func _decodeRaw<JSONDecoder: PostgresJSONDecoder>(
        from byteBuffer: inout ByteBuffer?,
        type: PostgresDataType,
        format: PostgresFormat,
        context: PostgresDecodingContext<JSONDecoder>
    ) throws -> Self  

Requirements

_Decodable​Type

associatedtype _DecodableType: PostgresDecodable = Self

A type definition of the type that actually implements the PostgresDecodable protocol. This is an escape hatch to prevent a cycle in the conformace of the Optional type to PostgresDecodable.

String? should be PostgresDecodable, String?? should not be PostgresDecodable

init(from:​type:​format:​context:​)

init<JSONDecoder: PostgresJSONDecoder>(
        from byteBuffer: inout ByteBuffer,
        type: PostgresDataType,
        format: PostgresFormat,
        context: PostgresDecodingContext<JSONDecoder>
    ) throws

Create an entity from the byteBuffer in postgres wire format

Parameters

byte​Buffer inout Byte​Buffer

A ByteBuffer to decode. The byteBuffer is sliced in such a way that it is expected that the complete buffer is consumed for decoding

type Postgres​Data​Type

The postgres data type. Depending on this type the byteBuffer's bytes need to be interpreted in different ways.

format Postgres​Format

The postgres wire format. Can be .text or .binary

context Postgres​Decoding​Context<JSONDecoder>

A PSQLDecodingContext providing context for decoding. This includes a JSONDecoder to use when decoding json and metadata to create better errors.

Returns

A decoded object

_decode​Raw(from:​type:​format:​context:​)

static func _decodeRaw<JSONDecoder: PostgresJSONDecoder>(
        from byteBuffer: inout ByteBuffer?,
        type: PostgresDataType,
        format: PostgresFormat,
        context: PostgresDecodingContext<JSONDecoder>
    ) throws -> Self

Decode an entity from the byteBuffer in postgres wire format. This method has a default implementation and is only overwritten for Optionals. Other than in the