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 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::from_int

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

    AuthenticationCleartextPassword

    pub(all) struct AuthenticationCleartextPassword {
    }

    PostgreSQL AuthenticationCleartextPassword (B).

    AuthenticationMD5Password

    pub(all) struct AuthenticationMD5Password {
    salt : Bytes
    }

    PostgreSQL AuthenticationMD5Password (B).

    AuthenticationOk

    pub(all) struct AuthenticationOk {
    }

    PostgreSQL AuthenticationOk (B).

    AuthenticationSASL

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

    PostgreSQL AuthenticationSASL (B).

    AuthenticationSASLContinue

    pub(all) struct AuthenticationSASLContinue {
    data : Bytes
    }

    PostgreSQL AuthenticationSASLContinue (B).

    AuthenticationSASLFinal

    pub(all) struct AuthenticationSASLFinal {
    data : Bytes
    }

    PostgreSQL AuthenticationSASLFinal (B).

    BackendKeyData

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

    PostgreSQL BackendKeyData (B).

    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

    BindComplete

    pub(all) struct BindComplete {
    }

    PostgreSQL BindComplete (B).

    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

    CloseComplete

    pub(all) struct CloseComplete {
    }

    PostgreSQL CloseComplete (B).

    CommandComplete

    pub(all) struct CommandComplete {
    tag : CommandTag
    }

    PostgreSQL CommandComplete (B).

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

    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::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.

    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
    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, 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.

    CopyBothResponse

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

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

    CopyData

    pub(all) struct CopyData {
    data : Bytes
    }

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

    CopyDone

    pub(all) struct CopyDone {
    }

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

    CopyFail

    pub(all) struct CopyFail {
    message : String
    }

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

    CopyInResponse

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

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

    CopyOutResponse

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

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

    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

    Describe

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

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

    EmptyQueryResponse

    pub(all) struct EmptyQueryResponse {
    }

    PostgreSQL EmptyQueryResponse (B).

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

    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::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

    FieldDescription

    pub 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.

    Flush

    pub(all) struct Flush {
    }

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

    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.

    NoData

    pub(all) struct NoData {
    }

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

    NoticeResponse

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

    PostgreSQL NoticeResponse (B).

    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.

    ParameterDescription

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

    PostgreSQL ParameterDescription (B).

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

    ParameterStatus

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

    PostgreSQL ParameterStatus (B).

    Parse

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

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

    ParseComplete

    pub(all) struct ParseComplete {
    }

    PostgreSQL ParseComplete (B).

    PasswordMessage

    pub(all) struct PasswordMessage {
    password : String
    }

    PostgreSQL PasswordMessage (F).

    PortalSuspended

    pub(all) struct PortalSuspended {
    }

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

    ProtocolVersion

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

    PostgreSQL protocol version constants.

    ProtocolVersion::minor

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

    ProtocolVersion::to_int32

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

    Query

    pub(all) struct Query {
    sql : String
    }

    PostgreSQL Query (F).
    impl Message for Query

    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
    }

    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_params

    async fn RawConn::execute_params(self : RawConn, sql : String, param_values : Array[Bytes?], param_oids : Array[Int], 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".

    • param_values — one element per $n placeholder. None = SQL NULL. Values must already be encoded per the corresponding format code.

    The reader must be consumed (via read / has_next+close) or explicitly closed before RawConn can be used for another query.

    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 named prepared statement via the extended query protocol.

    Sends Bind (unnamed portal ← named statement) + Describe(P) + Execute + Sync, then reads BindComplete + RowDescription/NoData and returns a ResultReader for streaming rows.

    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 — 0 = text, 1 = binary. Same convention.

    Call execute_statement instead if you already have a StatementDescription — it skips the Describe round-trip.

    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 — 0 = text, 1 = binary. Same convention.

    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.

    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).

    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).

    SASLInitialResponse

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

    PostgreSQL SASLInitialResponse (F).

    SASLResponse

    pub(all) struct SASLResponse {
    data : Bytes
    }

    PostgreSQL SASLResponse (F).

    SSLRequest

    pub(all) struct SSLRequest {
    }

    PostgreSQL SSLRequest (F).

    StartupMessage

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

    PostgreSQL StartupMessage (F).

    StatementDescription

    pub 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

    Sync

    pub(all) struct Sync {
    }

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

    Terminate

    pub(all) struct Terminate {
    }

    PostgreSQL Terminate (F).

    TransactionStatus

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

    Transaction status indicator from ReadyForQuery.

    TransactionStatus::from_byte

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

    TransactionStatus::to_byte

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

    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.