postgleam/message

Types

Authentication request types

pub type AuthType {
  AuthOk
  AuthKerberos
  AuthCleartext
  AuthMd5(salt: BitArray)
  AuthScm
  AuthGss
  AuthGssContinue(data: BitArray)
  AuthSspi
  AuthSasl(mechanisms: List(String))
  AuthSaslContinue(data: BitArray)
  AuthSaslFinal(data: BitArray)
}

Constructors

  • AuthOk
  • AuthKerberos
  • AuthCleartext
  • AuthMd5(salt: BitArray)
  • AuthScm
  • AuthGss
  • AuthGssContinue(data: BitArray)
  • AuthSspi
  • AuthSasl(mechanisms: List(String))
  • AuthSaslContinue(data: BitArray)
  • AuthSaslFinal(data: BitArray)

Messages sent from PostgreSQL backend to client

pub type BackendMessage {
  AuthenticationMsg(auth: AuthType)
  BackendKeyData(pid: Int, key: Int)
  ReadyForQuery(status: TransactionStatus)
  ParameterStatus(name: String, value: String)
  RowDescription(fields: List(RowField))
  DataRow(values: BitArray)
  CommandComplete(tag: String)
  ParseComplete
  BindComplete
  CloseComplete
  NoData
  PortalSuspended
  EmptyQueryResponse
  ErrorResponse(fields: dict.Dict(String, String))
  NoticeResponse(fields: dict.Dict(String, String))
  NotificationResponse(
    pg_pid: Int,
    channel: String,
    payload: String,
  )
  ParameterDescription(type_oids: List(Int))
  CopyInResponse(format: Format, columns: List(Format))
  CopyOutResponse(format: Format, columns: List(Format))
  CopyBothResponse(format: Format, columns: List(Format))
  CopyData(data: BitArray)
  CopyDone
}

Constructors

  • AuthenticationMsg(auth: AuthType)
  • BackendKeyData(pid: Int, key: Int)
  • ReadyForQuery(status: TransactionStatus)
  • ParameterStatus(name: String, value: String)
  • RowDescription(fields: List(RowField))
  • DataRow(values: BitArray)
  • CommandComplete(tag: String)
  • ParseComplete
  • BindComplete
  • CloseComplete
  • NoData
  • PortalSuspended
  • EmptyQueryResponse
  • ErrorResponse(fields: dict.Dict(String, String))
  • NoticeResponse(fields: dict.Dict(String, String))
  • NotificationResponse(
      pg_pid: Int,
      channel: String,
      payload: String,
    )
  • ParameterDescription(type_oids: List(Int))
  • CopyInResponse(format: Format, columns: List(Format))
  • CopyOutResponse(format: Format, columns: List(Format))
  • CopyBothResponse(format: Format, columns: List(Format))
  • CopyData(data: BitArray)
  • CopyDone

Result of trying to decode a message from a byte buffer

pub type DecodeResult {
  Decoded(message: BackendMessage, rest: BitArray)
  Incomplete
  DecodeFailed(reason: String)
}

Constructors

  • Decoded(message: BackendMessage, rest: BitArray)

    Successfully decoded a message, with remaining bytes

  • Incomplete

    Not enough data yet — need more bytes

  • DecodeFailed(reason: String)

    Unrecoverable decode error

Describe target type

pub type DescribeType {
  DescribeStatement
  DescribePortal
}

Constructors

  • DescribeStatement
  • DescribePortal

Format code for column data

pub type Format {
  TextFormat
  BinaryFormat
}

Constructors

  • TextFormat
  • BinaryFormat

Messages sent from client to PostgreSQL backend

pub type FrontendMessage {
  StartupMessage(params: List(#(String, String)))
  PasswordMessage(password: String)
  SASLInitialResponse(mechanism: String, data: BitArray)
  SASLResponse(data: BitArray)
  SimpleQuery(statement: String)
  Parse(name: String, statement: String, type_oids: List(Int))
  Describe(type_: DescribeType, name: String)
  Bind(
    portal: String,
    statement: String,
    param_formats: List(Format),
    params: List(option.Option(BitArray)),
    result_formats: List(Format),
  )
  Execute(portal: String, max_rows: Int)
  Close(type_: DescribeType, name: String)
  Sync
  Flush
  Terminate
  SSLRequest
  CancelRequest(pid: Int, key: Int)
  CopyDataMsg(data: BitArray)
  CopyDoneMsg
  CopyFail(message: String)
}

Constructors

  • StartupMessage(params: List(#(String, String)))
  • PasswordMessage(password: String)
  • SASLInitialResponse(mechanism: String, data: BitArray)
  • SASLResponse(data: BitArray)
  • SimpleQuery(statement: String)
  • Parse(name: String, statement: String, type_oids: List(Int))
  • Describe(type_: DescribeType, name: String)
  • Bind(
      portal: String,
      statement: String,
      param_formats: List(Format),
      params: List(option.Option(BitArray)),
      result_formats: List(Format),
    )
  • Execute(portal: String, max_rows: Int)
  • Close(type_: DescribeType, name: String)
  • Sync
  • Flush
  • Terminate
  • SSLRequest
  • CancelRequest(pid: Int, key: Int)
  • CopyDataMsg(data: BitArray)
  • CopyDoneMsg
  • CopyFail(message: String)

A field descriptor in a RowDescription

pub type RowField {
  RowField(
    name: String,
    table_oid: Int,
    column: Int,
    type_oid: Int,
    type_size: Int,
    type_mod: Int,
    format: Format,
  )
}

Constructors

  • RowField(
      name: String,
      table_oid: Int,
      column: Int,
      type_oid: Int,
      type_size: Int,
      type_mod: Int,
      format: Format,
    )

Transaction status reported by ReadyForQuery

pub type TransactionStatus {
  Idle
  InTransaction
  FailedTransaction
}

Constructors

  • Idle
  • InTransaction
  • FailedTransaction

Values

pub fn decode_backend(buffer: BitArray) -> DecodeResult

Try to decode one backend message from a byte buffer. Returns Decoded(msg, remaining_bytes), Incomplete, or DecodeFailed.

pub fn decode_cstring(
  data: BitArray,
) -> Result(#(String, BitArray), Nil)

Decode a null-terminated C string from a BitArray. Returns the string and the remaining bytes after the null terminator.

pub fn encode_frontend(msg: FrontendMessage) -> BitArray

Encode a frontend message to bytes ready to send on the wire

pub fn extract_row_values(
  values: BitArray,
) -> List(option.Option(BitArray))

Extract column values from a DataRow’s raw value bytes. Returns a list of Option(BitArray) — None for NULL columns.

Search Document