Sign in

    jaredzhou/moonpg/wire does not have a README file

    Message

    pub(open) trait Message {
    fn encode(Self) -> Bytes raise WireError
    fn decode(BytesView) -> Self raise WireError
    fn describe(Self) -> String
    }

    Trait for PostgreSQL wire-protocol messages.

    Every message knows how to encode itself to wire-format Bytes and decode itself from wire-format Bytes.

    Transport

    pub(open) trait Transport :
    Reader
    +
    Writer
    {
    fn close(Self) -> Unit
    }

    A bidirectional stream that can be closed.

    Supertrait of @io.Reader + @io.Writer with an explicit close method.

    WireError

    pub(all) suberror WireError {
    PgServer(String)
    Connect(String)
    Auth(String)
    Parse(String)
    InvalidMessage(String)
    IO(String)
    }

    Wire-protocol errors.

    AuthMethod

    pub(all) enum AuthMethod {
    Ok
    CleartextPassword
    MD5Password
    SASL
    SASLContinue
    SASLFinal
    } derive(Eq,
    Debug
    )

    Authentication method requested by the server.

    AuthMethod::equal

    fn AuthMethod::equal(AuthMethod, AuthMethod) -> Bool

    AuthMethod::from_int

    fn AuthMethod::from_int(v : Int) -> AuthMethod raise WireError

    AuthMethod::not_equal

    fn AuthMethod::not_equal(x : AuthMethod, y : AuthMethod) -> Bool

    AuthenticationCleartextPassword

    pub(all) struct AuthenticationCleartextPassword {
    }

    PostgreSQL AuthenticationCleartextPassword (B).

    AuthenticationCleartextPassword::decode

    AuthenticationCleartextPassword::describe

    AuthenticationCleartextPassword::encode

    AuthenticationMD5Password

    pub(all) struct AuthenticationMD5Password {
    salt : Bytes
    }

    PostgreSQL AuthenticationMD5Password (B).

    AuthenticationMD5Password::decode

    fn AuthenticationMD5Password::decode(payload : BytesView) -> AuthenticationMD5Password raise WireError

    AuthenticationMD5Password::describe

    AuthenticationMD5Password::encode

    AuthenticationOk

    pub(all) struct AuthenticationOk {
    }

    PostgreSQL AuthenticationOk (B).

    AuthenticationOk::decode

    fn AuthenticationOk::decode(_payload : BytesView) -> AuthenticationOk raise WireError

    AuthenticationOk::describe

    fn AuthenticationOk::describe(_self : AuthenticationOk) -> String

    AuthenticationOk::encode

    fn AuthenticationOk::encode(_self : AuthenticationOk) -> Bytes raise WireError

    AuthenticationSASL

    pub(all) struct AuthenticationSASL {
    mechanisms : Array[String]
    }

    PostgreSQL AuthenticationSASL (B).

    AuthenticationSASL::decode

    fn AuthenticationSASL::decode(payload : BytesView) -> AuthenticationSASL raise WireError

    AuthenticationSASL::describe

    fn AuthenticationSASL::describe(self : AuthenticationSASL) -> String

    AuthenticationSASL::encode

    fn AuthenticationSASL::encode(self : AuthenticationSASL) -> Bytes raise WireError

    AuthenticationSASLContinue

    pub(all) struct AuthenticationSASLContinue {
    data : Bytes
    }

    PostgreSQL AuthenticationSASLContinue (B).

    AuthenticationSASLContinue::decode

    fn AuthenticationSASLContinue::decode(payload : BytesView) -> AuthenticationSASLContinue raise WireError

    AuthenticationSASLContinue::describe

    AuthenticationSASLContinue::encode

    AuthenticationSASLFinal

    pub(all) struct AuthenticationSASLFinal {
    data : Bytes
    }

    PostgreSQL AuthenticationSASLFinal (B).

    AuthenticationSASLFinal::decode

    fn AuthenticationSASLFinal::decode(payload : BytesView) -> AuthenticationSASLFinal raise WireError

    AuthenticationSASLFinal::describe

    fn AuthenticationSASLFinal::describe(self : AuthenticationSASLFinal) -> String

    AuthenticationSASLFinal::encode

    BackendKeyData

    pub(all) struct BackendKeyData {
    pid : Int
    secret_key : Int
    }

    PostgreSQL BackendKeyData (B).

    BackendKeyData::decode

    fn BackendKeyData::decode(payload : BytesView) -> BackendKeyData raise WireError

    BackendKeyData::describe

    fn BackendKeyData::describe(self : BackendKeyData) -> String

    BackendKeyData::encode

    fn BackendKeyData::encode(self : BackendKeyData) -> Bytes raise WireError

    BackendMessage

    pub(all) enum BackendMessage {
    AuthenticationOk(AuthenticationOk)
    AuthenticationCleartextPassword(AuthenticationCleartextPassword)
    AuthenticationMD5Password(AuthenticationMD5Password)
    AuthenticationSASL(AuthenticationSASL)
    AuthenticationSASLContinue(AuthenticationSASLContinue)
    AuthenticationSASLFinal(AuthenticationSASLFinal)
    BackendKeyData(BackendKeyData)
    ReadyForQuery(ReadyForQuery)
    ParameterStatus(ParameterStatus)
    ErrorResponse(ErrorResponse)
    NoticeResponse(NoticeResponse)
    RowDescription(RowDescription)
    DataRow(DataRow)
    CommandComplete(CommandComplete)
    EmptyQueryResponse(EmptyQueryResponse)
    ParseComplete(ParseComplete)
    BindComplete(BindComplete)
    CloseComplete(CloseComplete)
    ParameterDescription(ParameterDescription)
    NoData(NoData)
    PortalSuspended(PortalSuspended)
    CopyInResponse(CopyInResponse)
    CopyOutResponse(CopyOutResponse)
    CopyBothResponse(CopyBothResponse)
    CopyData(CopyData)
    CopyDone(CopyDone)
    NotificationResponse(NotificationResponse)
    NegotiateProtocolVersion(NegotiateProtocolVersion)
    Unknown(Byte, BytesView)
    }

    Tagged union of all backend (server → client) messages.

    Each variant wraps a concrete message struct that implements Message.

    BackendMessage::describe

    fn BackendMessage::describe(self : BackendMessage) -> String

    Bind

    pub(all) struct Bind {
    portal : String
    statement : String
    param_formats : Array[Int]
    params : Array[Bytes?]
    result_formats : Array[Int]
    }

    PostgreSQL Bind (F) — creates a portal from a prepared statement.
    impl Message for Bind

    Bind::decode

    fn Bind::decode(payload : BytesView) -> Bind raise WireError

    Bind::describe

    fn Bind::describe(self : Bind) -> String

    Bind::encode

    fn Bind::encode(self : Bind) -> Bytes raise WireError

    BindComplete

    pub(all) struct BindComplete {
    }

    PostgreSQL BindComplete (B).

    BindComplete::decode

    fn BindComplete::decode(_payload : BytesView) -> BindComplete raise WireError

    BindComplete::describe

    fn BindComplete::describe(_self : BindComplete) -> String

    BindComplete::encode

    fn BindComplete::encode(_self : BindComplete) -> Bytes raise WireError

    BytesMut

    pub(all) struct BytesMut {
    // private fields
    }

    Mutable byte buffer with random-access writes, built on Array[Byte].

    Unlike Buffer (append-only), BytesMut allows writing at any position. Convert to immutable Bytes via to_bytes() (one copy).

    The typical wire-protocol pattern:

    1. append type byte + placeholder length
    2. append payload
    3. overwrite the length bytes via set_*
    4. to_bytes() for the final wire-format Bytes

    BytesMut::append_byte

    fn BytesMut::append_byte(self : BytesMut, b : Byte) -> Unit

    Append a single byte.

    BytesMut::append_bytes

    fn BytesMut::append_bytes(self : BytesMut, b : Bytes) -> Unit

    Append raw bytes.

    BytesMut::append_int_be

    fn BytesMut::append_int_be(self : BytesMut, v : Int) -> Unit

    Append a 32-bit big-endian integer (4 bytes).

    BytesMut::append_string_null

    fn BytesMut::append_string_null(self : BytesMut, s : String) -> Unit

    Append a null-terminated UTF-8 string.

    BytesMut::len

    fn BytesMut::len(self : BytesMut) -> Int

    BytesMut::new

    fn BytesMut::new() -> BytesMut

    BytesMut::set_byte

    fn BytesMut::set_byte(self : BytesMut, pos : Int, b : Byte) -> Unit

    Overwrite a single byte at pos. Pads with zeros if pos >= len.

    BytesMut::set_int_be

    fn BytesMut::set_int_be(self : BytesMut, pos : Int, v : Int) -> Unit

    Write a 32-bit big-endian integer at pos (overwrites 4 bytes).

    BytesMut::to_bytes

    fn BytesMut::to_bytes(self : BytesMut) -> Bytes

    Convert to immutable Bytes. One copy (Bytes::from_array).

    Close

    pub(all) struct Close {
    variant : Byte
    name : String
    }

    Close a prepared statement (b'S') or portal (b'P').
    impl Message for Close

    Close::decode

    fn Close::decode(payload : BytesView) -> Close raise WireError

    Close::describe

    fn Close::describe(self : Close) -> String

    Close::encode

    fn Close::encode(self : Close) -> Bytes raise WireError

    CloseComplete

    pub(all) struct CloseComplete {
    }

    PostgreSQL CloseComplete (B).

    CloseComplete::decode

    fn CloseComplete::decode(_payload : BytesView) -> CloseComplete raise WireError

    CloseComplete::describe

    fn CloseComplete::describe(_self : CloseComplete) -> String

    CloseComplete::encode

    fn CloseComplete::encode(_self : CloseComplete) -> Bytes raise WireError

    CommandComplete

    pub(all) struct CommandComplete {
    tag : CommandTag
    }

    PostgreSQL CommandComplete (B).

    The tag describes the completed command, e.g. "SELECT 1", "INSERT 0 1".

    CommandComplete::decode

    fn CommandComplete::decode(payload : BytesView) -> CommandComplete raise WireError

    CommandComplete::describe

    fn CommandComplete::describe(self : CommandComplete) -> String

    CommandComplete::encode

    fn CommandComplete::encode(self : CommandComplete) -> Bytes raise WireError

    CommandTag

    pub struct CommandTag {
    tag : String
    }

    Parsed command-completion tag from CommandComplete.

    PostgreSQL returns tags like "SELECT 1", "INSERT 0 1", "DELETE 5".
    impl Show for CommandTag

    CommandTag::command

    fn CommandTag::command(self : CommandTag) -> String

    The SQL command word, e.g. "SELECT", "INSERT", "DELETE".

    CommandTag::new

    fn CommandTag::new(tag : String) -> CommandTag

    CommandTag::output

    fn CommandTag::output(self : CommandTag, logger : &Logger) -> Unit

    CommandTag::raw

    fn CommandTag::raw(self : CommandTag) -> String

    The raw tag string as sent by the server.

    CommandTag::rows_affected

    fn CommandTag::rows_affected(self : CommandTag) -> Int?

    Number of rows affected, if the tag includes a row count.

    For SELECT 1 returns Some(1), for INSERT 0 3 returns Some(3), for CREATE TABLE returns None.

    CommandTag::to_string

    fn CommandTag::to_string(self : CommandTag) -> String

    Config

    pub(all) struct Config {
    host : String
    hostaddr : String?
    port : Int
    user : String
    database : String?
    password : String?
    sslmode : String
    sslrootcert : String?
    sslcert : String?
    sslkey : String?
    application_name : String?
    connect_timeout : Int
    statement_timeout : Int
    read_timeout : Int
    target_session_attrs : String
    trace : Bool
    }

    PostgreSQL connection configuration.

    Two connection-string formats are accepted, mirroring libpq's fe-connect.c:

    URI (parsed via @url.parse):
    postgresql://[user[:password]@][host][:port][/dbname][?param=value&...]

    Keyword/Value:
    host=localhost port=5432 user=alice dbname=mydb password=secret
    Values may be single-quoted ('has spaces') and use backslash escaping.

    Config::from_connstr

    fn Config::from_connstr(s : String) -> Config raise WireError

    Parse a PostgreSQL connection string.

    Auto-detects URI (postgresql:// / postgres://) vs keyword/value format.

    Config::new

    fn Config::new(user : String, host? : String, hostaddr? : String?, port? : Int, database? : String?, password? : String?, sslmode? : String, sslrootcert? : String?, sslcert? : String?, sslkey? : String?, application_name? : String?, connect_timeout? : Int, statement_timeout? : Int, read_timeout? : Int, target_session_attrs? : String, trace? : Bool) -> Config

    Create a Config with explicit parameter values.

    ConnParam

    pub(all) struct ConnParam {
    key : String
    value : String
    }

    A key-value parameter pair used in StartupMessage.

    ConnStatus

    pub enum ConnStatus {
    Connecting
    Closed
    Idle
    Busy
    } derive(Eq,
    Debug
    )

    Connection lifecycle states.

    ConnStatus::equal

    fn ConnStatus::equal(ConnStatus, ConnStatus) -> Bool

    ConnStatus::not_equal

    fn ConnStatus::not_equal(x : ConnStatus, y : ConnStatus) -> Bool

    CopyBothResponse

    pub(all) struct CopyBothResponse {
    overall_format : Int
    column_formats : Array[Int]
    }

    PostgreSQL CopyBothResponse (B) — server is ready for both COPY directions.

    CopyBothResponse::decode

    fn CopyBothResponse::decode(payload : BytesView) -> CopyBothResponse raise WireError

    CopyBothResponse::describe

    fn CopyBothResponse::describe(_self : CopyBothResponse) -> String

    CopyBothResponse::encode

    fn CopyBothResponse::encode(self : CopyBothResponse) -> Bytes raise WireError

    CopyData

    pub(all) struct CopyData {
    data : Bytes
    }

    PostgreSQL CopyData (F) — data row for COPY ... FROM STDIN.
    impl Message for CopyData

    CopyData::decode

    fn CopyData::decode(_payload : BytesView) -> CopyData raise WireError

    CopyData::describe

    fn CopyData::describe(_self : CopyData) -> String

    CopyData::encode

    fn CopyData::encode(self : CopyData) -> Bytes raise WireError

    CopyDone

    pub(all) struct CopyDone {
    }

    PostgreSQL CopyDone (F) — signal end of COPY data.
    impl Message for CopyDone

    CopyDone::decode

    fn CopyDone::decode(_payload : BytesView) -> CopyDone raise WireError

    CopyDone::describe

    fn CopyDone::describe(_self : CopyDone) -> String

    CopyDone::encode

    fn CopyDone::encode(_self : CopyDone) -> Bytes raise WireError

    CopyFail

    pub(all) struct CopyFail {
    message : String
    }

    PostgreSQL CopyFail (F) — abort COPY with an error message.
    impl Message for CopyFail

    CopyFail::decode

    fn CopyFail::decode(_payload : BytesView) -> CopyFail raise WireError

    CopyFail::describe

    fn CopyFail::describe(_self : CopyFail) -> String

    CopyFail::encode

    fn CopyFail::encode(self : CopyFail) -> Bytes raise WireError

    CopyInResponse

    pub(all) struct CopyInResponse {
    overall_format : Int
    column_formats : Array[Int]
    }

    PostgreSQL CopyInResponse (B) — server is ready to receive COPY data.

    CopyInResponse::decode

    fn CopyInResponse::decode(payload : BytesView) -> CopyInResponse raise WireError

    CopyInResponse::describe

    fn CopyInResponse::describe(_self : CopyInResponse) -> String

    CopyInResponse::encode

    fn CopyInResponse::encode(self : CopyInResponse) -> Bytes raise WireError

    CopyOutResponse

    pub(all) struct CopyOutResponse {
    overall_format : Int
    column_formats : Array[Int]
    }

    PostgreSQL CopyOutResponse (B) — server is sending COPY data.

    CopyOutResponse::decode

    fn CopyOutResponse::decode(payload : BytesView) -> CopyOutResponse raise WireError

    CopyOutResponse::describe

    fn CopyOutResponse::describe(_self : CopyOutResponse) -> String

    CopyOutResponse::encode

    fn CopyOutResponse::encode(self : CopyOutResponse) -> Bytes raise WireError

    DataRow

    pub(all) struct DataRow {
    values : Array[Bytes?]
    }

    PostgreSQL DataRow (B).

    Each column value is Some(bytes) for non-NULL or None for NULL. Values are owned Bytes — safe to hold across message boundaries.
    impl Message for DataRow

    DataRow::decode

    fn DataRow::decode(payload : BytesView) -> DataRow raise WireError

    DataRow::describe

    fn DataRow::describe(self : DataRow) -> String

    DataRow::encode

    fn DataRow::encode(self : DataRow) -> Bytes raise WireError

    Describe

    pub(all) struct Describe {
    variant : Byte
    name : String
    }

    Describe a prepared statement (b'S') or portal (b'P').
    impl Message for Describe

    Describe::decode

    fn Describe::decode(payload : BytesView) -> Describe raise WireError

    Describe::describe

    fn Describe::describe(self : Describe) -> String

    Describe::encode

    fn Describe::encode(self : Describe) -> Bytes raise WireError

    EmptyQueryResponse

    pub(all) struct EmptyQueryResponse {
    }

    PostgreSQL EmptyQueryResponse (B).

    Sent when the query string is empty or whitespace-only.

    EmptyQueryResponse::decode

    fn EmptyQueryResponse::decode(_payload : BytesView) -> EmptyQueryResponse raise WireError

    EmptyQueryResponse::describe

    fn EmptyQueryResponse::describe(_self : EmptyQueryResponse) -> String

    EmptyQueryResponse::encode

    fn EmptyQueryResponse::encode(_self : EmptyQueryResponse) -> Bytes raise WireError

    ErrorField

    pub(all) struct ErrorField {
    field_type : Byte
    value : String
    } derive(
    Debug
    )

    A single typed field in an ErrorResponse or NoticeResponse.

    ErrorResponse

    pub(all) struct ErrorResponse {
    fields : Array[ErrorField]
    }

    PostgreSQL ErrorResponse (B).

    ErrorResponse::code

    fn ErrorResponse::code(self : ErrorResponse) -> String?

    ErrorResponse::decode

    fn ErrorResponse::decode(payload : BytesView) -> ErrorResponse raise WireError

    ErrorResponse::describe

    fn ErrorResponse::describe(self : ErrorResponse) -> String

    ErrorResponse::encode

    fn ErrorResponse::encode(self : ErrorResponse) -> Bytes raise WireError

    ErrorResponse::message

    fn ErrorResponse::message(self : ErrorResponse) -> String?

    ErrorResponse::severity

    fn ErrorResponse::severity(self : ErrorResponse) -> String?

    Execute

    pub(all) struct Execute {
    portal : String
    max_rows : Int
    }

    PostgreSQL Execute (F) — runs a portal.
    impl Message for Execute

    Execute::decode

    fn Execute::decode(payload : BytesView) -> Execute raise WireError

    Execute::describe

    fn Execute::describe(self : Execute) -> String

    Execute::encode

    fn Execute::encode(self : Execute) -> Bytes raise WireError

    FieldDescription

    pub(all) struct FieldDescription {
    name : String
    table_oid : Int
    attr_num : Int
    type_oid : Int
    typlen : Int
    typmod : Int
    format : Int
    }

    Per-field metadata carried in a RowDescription message.

    FieldDescription::type_name

    fn FieldDescription::type_name(self : FieldDescription) -> String

    Return the human-readable type name for this column (e.g. "int4", "text"). Looks up type_oid in the built-in OID map; returns "unknown" for unrecognised OIDs. No database round-trip.

    Flush

    pub(all) struct Flush {
    }

    PostgreSQL Flush (F) — flush server output buffer without Sync's transaction effects.
    impl Message for Flush

    Flush::decode

    fn Flush::decode(_payload : BytesView) -> Flush raise WireError

    Flush::describe

    fn Flush::describe(_self : Flush) -> String

    Flush::encode

    fn Flush::encode(_self : Flush) -> Bytes raise WireError

    NegotiateProtocolVersion

    pub(all) struct NegotiateProtocolVersion {
    newest_minor_version : Int
    options : Array[String]
    }

    PostgreSQL NegotiateProtocolVersion (B).

    Sent when the client requests a protocol version newer than the server supports within the same major version. The client should re-send its StartupMessage with the version offered by the server.

    NegotiateProtocolVersion::decode

    fn NegotiateProtocolVersion::decode(payload : BytesView) -> NegotiateProtocolVersion raise WireError

    NegotiateProtocolVersion::describe

    fn NegotiateProtocolVersion::describe(self : NegotiateProtocolVersion) -> String

    NegotiateProtocolVersion::encode

    NoData

    pub(all) struct NoData {
    }

    PostgreSQL NoData (B) — returned when Describe finds no result columns.
    impl Message for NoData

    NoData::decode

    fn NoData::decode(_payload : BytesView) -> NoData raise WireError

    NoData::describe

    fn NoData::describe(_self : NoData) -> String

    NoData::encode

    fn NoData::encode(_self : NoData) -> Bytes raise WireError

    NoticeResponse

    pub(all) struct NoticeResponse {
    fields : Array[ErrorField]
    }

    PostgreSQL NoticeResponse (B).

    NoticeResponse::decode

    fn NoticeResponse::decode(payload : BytesView) -> NoticeResponse raise WireError

    NoticeResponse::describe

    fn NoticeResponse::describe(self : NoticeResponse) -> String

    NoticeResponse::encode

    fn NoticeResponse::encode(self : NoticeResponse) -> Bytes raise WireError

    NoticeResponse::message

    fn NoticeResponse::message(self : NoticeResponse) -> String?

    NotificationResponse

    pub(all) struct NotificationResponse {
    pid : Int
    channel : String
    payload : String
    }

    PostgreSQL NotificationResponse (B).

    Sent when a NOTIFY command is executed for a channel the client is listening on (via LISTEN). Can arrive at any time — even during a query — so the driver queues them transparently.

    NotificationResponse::decode

    fn NotificationResponse::decode(payload : BytesView) -> NotificationResponse raise WireError

    NotificationResponse::describe

    fn NotificationResponse::describe(self : NotificationResponse) -> String

    NotificationResponse::encode

    fn NotificationResponse::encode(self : NotificationResponse) -> Bytes raise WireError

    ParameterDescription

    pub(all) struct ParameterDescription {
    param_types : Array[Int]
    }

    PostgreSQL ParameterDescription (B).

    Provides the OIDs of the parameters expected by a prepared statement.

    ParameterDescription::decode

    fn ParameterDescription::decode(payload : BytesView) -> ParameterDescription raise WireError

    ParameterDescription::describe

    fn ParameterDescription::describe(self : ParameterDescription) -> String

    ParameterDescription::encode

    fn ParameterDescription::encode(self : ParameterDescription) -> Bytes raise WireError

    ParameterStatus

    pub(all) struct ParameterStatus {
    name : String
    value : String
    }

    PostgreSQL ParameterStatus (B).

    ParameterStatus::decode

    fn ParameterStatus::decode(payload : BytesView) -> ParameterStatus raise WireError

    ParameterStatus::describe

    fn ParameterStatus::describe(self : ParameterStatus) -> String

    ParameterStatus::encode

    fn ParameterStatus::encode(self : ParameterStatus) -> Bytes raise WireError

    Parse

    pub(all) struct Parse {
    name : String
    query : String
    param_types : Array[Int]
    }

    PostgreSQL Parse (F) — creates a prepared statement.
    impl Message for Parse

    Parse::decode

    fn Parse::decode(payload : BytesView) -> Parse raise WireError

    Parse::describe

    fn Parse::describe(self : Parse) -> String

    Parse::encode

    fn Parse::encode(self : Parse) -> Bytes raise WireError

    ParseComplete

    pub(all) struct ParseComplete {
    }

    PostgreSQL ParseComplete (B).

    ParseComplete::decode

    fn ParseComplete::decode(_payload : BytesView) -> ParseComplete raise WireError

    ParseComplete::describe

    fn ParseComplete::describe(_self : ParseComplete) -> String

    ParseComplete::encode

    fn ParseComplete::encode(_self : ParseComplete) -> Bytes raise WireError

    PasswordMessage

    pub(all) struct PasswordMessage {
    password : String
    }

    PostgreSQL PasswordMessage (F).

    PasswordMessage::decode

    fn PasswordMessage::decode(payload : BytesView) -> PasswordMessage raise WireError

    PasswordMessage::describe

    fn PasswordMessage::describe(_self : PasswordMessage) -> String

    PasswordMessage::encode

    fn PasswordMessage::encode(self : PasswordMessage) -> Bytes raise WireError

    PortalSuspended

    pub(all) struct PortalSuspended {
    }

    PostgreSQL PortalSuspended (B) — Execute reached max_rows before the portal was fully consumed.

    PortalSuspended::decode

    fn PortalSuspended::decode(_payload : BytesView) -> PortalSuspended raise WireError

    PortalSuspended::describe

    fn PortalSuspended::describe(_self : PortalSuspended) -> String

    PortalSuspended::encode

    fn PortalSuspended::encode(_self : PortalSuspended) -> Bytes raise WireError

    ProtocolVersion

    pub enum ProtocolVersion {
    V3_0
    V3_2
    } derive(Eq,
    Debug
    )

    PostgreSQL protocol version constants.

    ProtocolVersion::equal

    ProtocolVersion::minor

    fn ProtocolVersion::minor(self : ProtocolVersion) -> Int

    ProtocolVersion::not_equal

    fn ProtocolVersion::not_equal(x : ProtocolVersion, y : ProtocolVersion) -> Bool

    ProtocolVersion::to_int32

    fn ProtocolVersion::to_int32(self : ProtocolVersion) -> Int

    Query

    pub(all) struct Query {
    sql : String
    }

    PostgreSQL Query (F).
    impl Message for Query

    Query::decode

    fn Query::decode(payload : BytesView) -> Query raise WireError

    Query::describe

    fn Query::describe(_self : Query) -> String

    Query::encode

    fn Query::encode(self : Query) -> Bytes raise WireError

    RawConn

    pub struct RawConn {
    stream : Stream
    trace : Bool
    host : String
    port : Int
    params :
    HashMap
    [String, String]
    pid : Int
    secret_key : Int
    tx_status : TransactionStatus
    status : ConnStatus
    read_timeout_ms : Int
    }

    Raw PostgreSQL wire-protocol connection.

    Handles TCP connection, SSL negotiation, startup message exchange, authentication, and message send/receive. After a successful handshake the connection is in the Idle state and can be used for queries.

    RawConn::backend_pid

    fn RawConn::backend_pid(self : RawConn) -> Int

    RawConn::begin_copy_in

    async fn RawConn::begin_copy_in(self : RawConn, sql : String) -> Unit raise WireError

    Begin a COPY ... FROM STDIN operation.

    Sends the query, locks the connection, and reads until CopyInResponse. After this, use send_copy_data to stream rows and end_copy_in to finish.

    RawConn::bind

    async fn RawConn::bind(self : RawConn, portal : String, statement : String, params : Array[Bytes?], param_formats : Array[Int], result_formats : Array[Int]) -> Unit raise WireError

    Bind a portal to a prepared statement, supplying concrete parameter values.

    portal — portal name (empty string = unnamed). statement — source prepared statement name (empty = unnamed). params — parameter values (None = SQL NULL). param_formats — 0 = text, 1 = binary. Empty array = all text; single element = applies to all. result_formats — 0 = text, 1 = binary. Same convention as param_formats.

    The server responds with BindComplete. Call describe_portal afterwards to get the result-column descriptions.

    RawConn::close

    fn RawConn::close(self : RawConn) -> Unit

    RawConn::close_portal

    async fn RawConn::close_portal(self : RawConn, name : String) -> Unit raise WireError

    Close a portal.

    RawConn::close_statement

    async fn RawConn::close_statement(self : RawConn, name : String) -> Unit raise WireError

    Close a prepared statement.

    RawConn::copy_in

    async fn RawConn::copy_in(self : RawConn, sql : String, rows : Iter[String]) -> Unit raise WireError

    Execute COPY ... FROM STDIN with rows from an iterator.

    Convenience wrapper around begin_copy_in + send_copy_data loop + end_copy_in. Rows are pulled from the iterator one at a time — only a single row is held in memory.

    RawConn::describe_portal

    async fn RawConn::describe_portal(self : RawConn, portal : String) -> Array[FieldDescription] raise WireError

    Describe a portal to learn its result-column layout.

    Returns the columns array suitable for passing to execute. Returns an empty array when the portal produces no result set (e.g. INSERT / UPDATE / DELETE).

    RawConn::describe_statement

    async fn RawConn::describe_statement(self : RawConn, name : String) -> Array[Int] raise WireError

    Describe a prepared statement to learn its parameter types.

    Returns integer OIDs for each parameter placeholder. Useful when the statement was prepared with param_types set to [] or [0].

    RawConn::end_copy_in

    async fn RawConn::end_copy_in(self : RawConn) -> Unit raise WireError

    Finish a COPY ... FROM STDIN operation.

    Sends CopyDone, then reads CommandComplete + ReadyForQuery and unlocks the connection. Pairs with begin_copy_in.

    RawConn::end_query

    async fn RawConn::end_query(self : RawConn) -> Unit raise WireError

    Drain remaining messages until ReadyForQuery, update tx_status, and unlock the connection. Pairs with start_query.

    If an ErrorResponse is encountered during drain, it finishes draining through to ReadyForQuery and then raises PgServer.

    RawConn::execute

    async fn RawConn::execute(self : RawConn, portal : String, columns : Array[FieldDescription], max_rows : Int) -> ResultReader raise WireError

    Execute a portal and return a ResultReader for pulling rows.

    Sends Execute followed by Sync so that ReadyForQuery follows naturally after the last row. The returned ResultReader streams DataRow messages and drains through ReadyForQuery on close.

    columns — obtained from a prior describe_portal call. max_rows — row limit; 0 = unlimited.

    RawConn::execute_prepared

    async fn RawConn::execute_prepared(self : RawConn, stmt_name : String, param_values : Array[Bytes?], param_formats : Array[Int], result_formats : Array[Int]) -> ResultReader raise WireError

    Execute a parameterized SQL command via the extended query protocol.

    An unnamed statement is parsed from sql, bound to an unnamed portal with the given parameter values, and executed. The returned ResultReader streams rows from the server.

    Parameter conventions (mirrors pgx ExecParams):

    • param_oids — OID for each parameter value. 0 = let the server infer. Must have length 0, 1 (applied to all), or equal to param_values. An empty array means "infer all".

    • param_formats — format code per parameter: 0 = text, 1 = binary. Must have length 0, 1 (applied to all), or equal to param_values. An empty array means "all text".

    • result_formats — format code per result column: 0 = text, 1 = binary. Must have length 0, 1 (applied to all), or equal to the number of result columns. An empty array means "all text".

    RawConn::execute_statement

    async fn RawConn::execute_statement(self : RawConn, stmt_desc : StatementDescription, param_values : Array[Bytes?], param_formats : Array[Int], result_formats? : Array[Int]) -> ResultReader raise WireError

    Execute a prepared statement using its StatementDescription.

    Unlike execute_prepared, this does not send a Describe message because the result-column layout is already known from the StatementDescription. Saves one network round-trip.

    param_values — one element per parameter placeholder. None = NULL. Values must already be encoded per the corresponding format code.

    param_formats — 0 = text, 1 = binary. Length must be 0, 1, or equal to param_values.

    result_formats — optional; when absent, synthesized from stmt_desc.fields[].format.

    RawConn::flush

    async fn RawConn::flush(self : RawConn) -> Unit raise WireError

    Send a Flush message to the server.

    Tells the server to flush any buffered output. Used in the extended query protocol.

    RawConn::is_busy

    fn RawConn::is_busy(self : RawConn) -> Bool

    RawConn::is_closed

    fn RawConn::is_closed(self : RawConn) -> Bool

    RawConn::param

    fn RawConn::param(self : RawConn, name : String) -> String?

    RawConn::prepare

    async fn RawConn::prepare(self : RawConn, name : String, sql : String, param_types : Array[Int]) -> StatementDescription raise WireError

    Create a prepared statement.

    Sends Parse + Describe(S) + Sync, then reads responses until ReadyForQuery. Returns a StatementDescription with the inferred parameter OIDs and result-column layout.

    If name is empty the unnamed statement is used, which is overwritten by the next Parse on that connection.

    param_types — OID for each parameter; 0 = leave type unspecified. An empty array means "infer all".

    RawConn::read_byte

    async fn RawConn::read_byte(self : RawConn) -> Byte

    Read a single byte from the stream. Used for the SSL negotiation response (S or N), which is not a framed message.

    RawConn::receive

    async fn RawConn::receive(self : RawConn) -> BackendMessage raise WireError

    Receive the next backend message from the server.

    Reads the 1-byte type tag, then the 4-byte length, then the payload, and decodes into a BackendMessage. Closes the connection on any I/O or protocol error, and applies read_timeout to every read.

    RawConn::receive_wait

    async fn RawConn::receive_wait(self : RawConn) -> BackendMessage raise WireError

    Receive the next backend message, ignoring read_timeout.

    For the LISTEN/NOTIFY loop, where a silent socket is the normal state: a channel can stay quiet for hours, so waiting is not a failure.

    RawConn::send

    async fn[M : Message] RawConn::send(self : RawConn, msg : M) -> Unit raise WireError

    Send any frontend message.

    Calls msg.encode() to get the wire-format bytes, then writes them to the socket. For StartupMessage and SSLRequest the message has no type byte; for all other messages the type byte is included.

    RawConn::send_copy_data

    async fn RawConn::send_copy_data(self : RawConn, data : Bytes) -> Unit raise WireError

    Send a CopyData message — a single row or chunk of COPY data.

    RawConn::send_copy_done

    async fn RawConn::send_copy_done(self : RawConn) -> Unit raise WireError

    Signal successful completion of COPY data transfer.

    RawConn::send_copy_fail

    async fn RawConn::send_copy_fail(self : RawConn, message : String) -> Unit raise WireError

    Abort a COPY operation with an error message.

    RawConn::set_trace

    fn RawConn::set_trace(self : RawConn, on : Bool) -> Unit

    Enable or disable protocol tracing.

    RawConn::simple_query

    async fn RawConn::simple_query(self : RawConn, sql : String) -> ResultReader raise WireError

    Execute a simple query and return a ResultReader.

    RawConn::start_query

    async fn RawConn::start_query(self : RawConn, sql : String) -> Unit raise WireError

    Begin a query: lock the connection and send the SQL.

    After start_query, read responses via receive, then call end_query to drain remaining messages and unlock.

    RawConn::status

    fn RawConn::status(self : RawConn) -> ConnStatus

    RawConn::sync

    async fn RawConn::sync(self : RawConn) -> Unit raise WireError

    Force the server to process all pending extended-query messages and return ReadyForQuery. Updates conn.tx_status.

    RawConn::terminate

    async fn RawConn::terminate(self : RawConn) -> Unit

    Send Terminate and close.

    RawConn::try_close

    async fn RawConn::try_close(self : RawConn) -> Unit

    Best-effort emergency close for unrecoverable errors.

    Use this when the connection cannot be safely reused:

    • I/O errors — broken pipe, connection reset, unexpected EOF.
    • Protocol desynchronisation — invalid message length/type, the stream cannot be trusted any more.
    • Authentication failures.
    • Server FATAL / PANIC errors (as opposed to recoverable ERROR).

    What it does:

    1. Immediately marks the connection Closed so nothing else tries to use it.
    2. Sends a cancel request on a new TCP connection so the server stops any in-flight query.
    3. Sends Terminate on the original connection.
    4. Closes the socket.

    Steps 2 and 3 run concurrently via @async.all. All errors are silently ignored — this is fire-and-forget cleanup.

    RawConn::tx_status

    fn RawConn::tx_status(self : RawConn) -> TransactionStatus

    ReadyForQuery

    pub(all) struct ReadyForQuery {
    status : TransactionStatus
    }

    PostgreSQL ReadyForQuery (B).

    ReadyForQuery::decode

    fn ReadyForQuery::decode(payload : BytesView) -> ReadyForQuery raise WireError

    ReadyForQuery::describe

    fn ReadyForQuery::describe(self : ReadyForQuery) -> String

    ReadyForQuery::encode

    fn ReadyForQuery::encode(self : ReadyForQuery) -> Bytes raise WireError

    Result

    pub struct Result {
    columns : Array[FieldDescription]
    rows : Array[Array[Bytes?]]
    tag : CommandTag
    }

    All rows from a query, collected eagerly.

    ResultReader

    pub struct ResultReader {
    conn : RawConn
    columns : Array[FieldDescription]
    row_values : Array[Bytes?]?
    closed : Bool
    tag : CommandTag?
    }

    Pull-based query result reader.

    Obtained from RawConn::simple_query. Two usage styles:

    Pull — iterate row by row:
    while r.has_next() { let row = r.data_row(); ... }
    let tag = r.close()

    Batch — read everything at once:
    let result = r.read()

    ResultReader::close

    async fn ResultReader::close(self : ResultReader) -> CommandTag raise WireError

    Close the reader: drain remaining rows and messages, unlock, return tag. Safe to call multiple times.

    ResultReader::columns

    ResultReader::data_row

    fn ResultReader::data_row(self : ResultReader) -> Array[Bytes?] raise WireError

    Return the row cached by the last has_next() call. Panics if has_next() was not called or returned false.

    ResultReader::has_next

    async fn ResultReader::has_next(self : ResultReader) -> Bool raise WireError

    Wait for the next row. Returns true if a row is available (call data_row to get it), false when all rows have been consumed.

    On false the remaining messages up to ReadyForQuery have already been drained and the connection unlocked.

    ResultReader::read

    async fn ResultReader::read(self : ResultReader) -> Result raise WireError

    Eagerly read all remaining rows into a Result.

    RowDescription

    pub(all) struct RowDescription {
    columns : Array[FieldDescription]
    }

    PostgreSQL RowDescription (B).

    RowDescription::decode

    fn RowDescription::decode(payload : BytesView) -> RowDescription raise WireError

    RowDescription::describe

    fn RowDescription::describe(self : RowDescription) -> String

    RowDescription::encode

    fn RowDescription::encode(self : RowDescription) -> Bytes raise WireError

    SASLInitialResponse

    pub(all) struct SASLInitialResponse {
    mechanism : String
    initial_response : Bytes
    }

    PostgreSQL SASLInitialResponse (F).

    SASLInitialResponse::decode

    fn SASLInitialResponse::decode(payload : BytesView) -> SASLInitialResponse raise WireError

    SASLInitialResponse::describe

    fn SASLInitialResponse::describe(self : SASLInitialResponse) -> String

    SASLInitialResponse::encode

    fn SASLInitialResponse::encode(self : SASLInitialResponse) -> Bytes raise WireError

    SASLResponse

    pub(all) struct SASLResponse {
    data : Bytes
    }

    PostgreSQL SASLResponse (F).

    SASLResponse::decode

    fn SASLResponse::decode(payload : BytesView) -> SASLResponse raise WireError

    SASLResponse::describe

    fn SASLResponse::describe(self : SASLResponse) -> String

    SASLResponse::encode

    fn SASLResponse::encode(self : SASLResponse) -> Bytes raise WireError

    SSLRequest

    pub(all) struct SSLRequest {
    }

    PostgreSQL SSLRequest (F).

    SSLRequest::decode

    fn SSLRequest::decode(payload : BytesView) -> SSLRequest raise WireError

    SSLRequest::describe

    fn SSLRequest::describe(_self : SSLRequest) -> String

    SSLRequest::encode

    fn SSLRequest::encode(_self : SSLRequest) -> Bytes raise WireError

    StartupMessage

    pub(all) struct StartupMessage {
    version : ProtocolVersion
    params : Array[ConnParam]
    }

    PostgreSQL StartupMessage (F).

    StartupMessage::decode

    fn StartupMessage::decode(payload : BytesView) -> StartupMessage raise WireError

    StartupMessage::describe

    fn StartupMessage::describe(self : StartupMessage) -> String

    StartupMessage::encode

    fn StartupMessage::encode(self : StartupMessage) -> Bytes raise WireError

    StatementDescription

    pub(all) struct StatementDescription {
    name : String
    sql : String
    param_oids : Array[Int]
    fields : Array[FieldDescription]
    }

    Describes a prepared statement: its parameter OIDs and result-column layout (if the statement returns rows).

    Stream

    Concrete transport — either a plain TCP connection or a TLS-wrapped one.
    impl Transport for Stream
    impl Reader for Stream
    impl Writer for Stream

    Stream::_direct_read

    async fn Stream::_direct_read(self : Stream, buf : FixedArray[Byte], offset~ : Int, max_len~ : Int) -> Int

    Stream::_get_internal_buffer

    Stream::close

    fn Stream::close(self : Stream) -> Unit

    Stream::drop

    async fn Stream::drop(self : Stream, len : Int) -> Int

    Stream::read

    async fn Stream::read(self : Stream, dst : FixedArray[Byte], offset? : Int, max_len? : Int) -> Int

    Stream::read_all

    async fn Stream::read_all(self : Stream) -> &
    Data

    Stream::read_exactly

    async fn Stream::read_exactly(self : Stream, len : Int) -> Bytes

    Stream::read_some

    async fn Stream::read_some(self : Stream, max_len? : Int) -> Bytes?

    Stream::read_until

    async fn Stream::read_until(self : Stream, sep : StringView) -> String?

    Stream::write

    async fn Stream::write(self : Stream, data : &
    Data
    ) -> Unit

    Stream::write_once

    async fn Stream::write_once(self : Stream, buf : Bytes, offset~ : Int, len~ : Int) -> Int

    Stream::write_reader

    async fn Stream::write_reader(self : Stream, reader : &
    Reader
    ) -> Unit

    Sync

    pub(all) struct Sync {
    }

    PostgreSQL Sync (F) — commit point; server responds with ReadyForQuery.
    impl Message for Sync

    Sync::decode

    fn Sync::decode(_payload : BytesView) -> Sync raise WireError

    Sync::describe

    fn Sync::describe(_self : Sync) -> String

    Sync::encode

    fn Sync::encode(_self : Sync) -> Bytes raise WireError

    Terminate

    pub(all) struct Terminate {
    }

    PostgreSQL Terminate (F).

    Terminate::decode

    fn Terminate::decode(_payload : BytesView) -> Terminate raise WireError

    Terminate::describe

    fn Terminate::describe(_self : Terminate) -> String

    Terminate::encode

    fn Terminate::encode(_self : Terminate) -> Bytes raise WireError

    TransactionStatus

    pub(all) enum TransactionStatus {
    Idle
    InBlock
    Failed
    } derive(Eq,
    Debug
    )

    Transaction status indicator from ReadyForQuery.

    TransactionStatus::equal

    TransactionStatus::from_byte

    fn TransactionStatus::from_byte(b : Byte) -> TransactionStatus raise WireError

    TransactionStatus::not_equal

    fn TransactionStatus::not_equal(x : TransactionStatus, y : TransactionStatus) -> Bool

    TransactionStatus::output

    fn TransactionStatus::output(self : TransactionStatus, logger : &Logger) -> Unit

    TransactionStatus::to_byte

    fn TransactionStatus::to_byte(self : TransactionStatus) -> Byte

    TransactionStatus::to_string

    fn TransactionStatus::to_string(self : TransactionStatus) -> String

    DEFAULT_PORT

    let DEFAULT_PORT : Int

    The default PostgreSQL TCP port.

    MSG_AUTHENTICATION

    let MSG_AUTHENTICATION : Byte

    Message type bytes (server → client).

    MSG_BACKEND_KEY_DATA

    let MSG_BACKEND_KEY_DATA : Byte

    MSG_BIND

    let MSG_BIND : Byte

    MSG_BIND_COMPLETE

    let MSG_BIND_COMPLETE : Byte

    MSG_CLOSE

    let MSG_CLOSE : Byte

    MSG_CLOSE_COMPLETE

    let MSG_CLOSE_COMPLETE : Byte

    MSG_COMMAND_COMPLETE

    let MSG_COMMAND_COMPLETE : Byte

    MSG_COPY_BOTH_RESPONSE

    let MSG_COPY_BOTH_RESPONSE : Byte

    MSG_COPY_DATA

    let MSG_COPY_DATA : Byte

    MSG_COPY_DONE

    let MSG_COPY_DONE : Byte

    MSG_COPY_FAIL

    let MSG_COPY_FAIL : Byte

    CopyFail is frontend-only (server never sends it).

    MSG_COPY_IN_RESPONSE

    let MSG_COPY_IN_RESPONSE : Byte

    MSG_COPY_OUT_RESPONSE

    let MSG_COPY_OUT_RESPONSE : Byte

    MSG_DATA_ROW

    let MSG_DATA_ROW : Byte

    MSG_DESCRIBE

    let MSG_DESCRIBE : Byte

    MSG_EMPTY_QUERY

    let MSG_EMPTY_QUERY : Byte

    MSG_ERROR_RESPONSE

    let MSG_ERROR_RESPONSE : Byte

    MSG_EXECUTE

    let MSG_EXECUTE : Byte

    MSG_FLUSH

    let MSG_FLUSH : Byte

    MSG_NEGOTIATE_PROTOCOL_VERSION

    let MSG_NEGOTIATE_PROTOCOL_VERSION : Byte

    NegotiateProtocolVersion ('v') — PG 17+ protocol version negotiation.

    MSG_NOTICE_RESPONSE

    let MSG_NOTICE_RESPONSE : Byte

    MSG_NOTIFICATION_RESPONSE

    let MSG_NOTIFICATION_RESPONSE : Byte

    MSG_NO_DATA

    let MSG_NO_DATA : Byte

    MSG_PARAMETER_DESCRIPTION

    let MSG_PARAMETER_DESCRIPTION : Byte

    MSG_PARAMETER_STATUS

    let MSG_PARAMETER_STATUS : Byte

    MSG_PARSE

    let MSG_PARSE : Byte

    MSG_PARSE_COMPLETE

    let MSG_PARSE_COMPLETE : Byte

    MSG_PASSWORD

    let MSG_PASSWORD : Byte

    Message type bytes (frontend → server).

    MSG_PORTAL_SUSPENDED

    let MSG_PORTAL_SUSPENDED : Byte

    MSG_QUERY

    let MSG_QUERY : Byte

    MSG_READY_FOR_QUERY

    let MSG_READY_FOR_QUERY : Byte

    MSG_ROW_DESCRIPTION

    let MSG_ROW_DESCRIPTION : Byte

    MSG_SYNC

    let MSG_SYNC : Byte

    MSG_TERMINATE

    let MSG_TERMINATE : Byte

    PARAM_CLIENT_ENCODING

    let PARAM_CLIENT_ENCODING : String

    PARAM_SERVER_ENCODING

    let PARAM_SERVER_ENCODING : String

    PARAM_SERVER_VERSION

    let PARAM_SERVER_VERSION : String

    Well-known server parameter names.

    PARAM_TIMEZONE

    let PARAM_TIMEZONE : String

    SSL_REQUEST_CODE

    let SSL_REQUEST_CODE : Int

    SSL request magic number.

    compute_md5_password

    fn compute_md5_password(password : String, user : String, salt : Bytes) -> String

    Compute the MD5 password response for PostgreSQL authentication.

    password — the plaintext password user — the database user name salt — the 4-byte salt from the server's AuthenticationMD5Password message

    Returns the "md5..." string to send in a PasswordMessage.

    connect

    async fn connect(connstr : String) -> RawConn raise WireError

    connect_config

    async fn connect_config(config : Config) -> RawConn raise WireError

    Connect using a Config struct.

    handle_sasl_auth

    async fn handle_sasl_auth(conn : RawConn, user : String, mechanisms : Array[String], password : String?) -> Unit raise WireError

    Validate SCRAM-SHA-256 availability and delegate to handle_scram_auth.

    handle_scram_auth

    async fn handle_scram_auth(conn : RawConn, user : String, password : String) -> Unit raise WireError

    Run the full SCRAM-SHA-256 handshake.