postgresql_protocol

This library parses and generates packages for the PostgreSQL Binary Protocol It also provides a basic connection abstraction, but this hasn’t been used outside of tests.

Types

Messages originating from the PostgreSQL backend (server)

pub type BackendMessage {
  BeBindComplete
  BeCloseComplete
  BeCommandComplete(Command, Int)
  BeCopyData(data: BitArray)
  BeCopyDone
  BeAuthenticationOk
  BeAuthenticationKerberosV5
  BeAuthenticationCleartextPassword
  BeAuthenticationMD5Password(salt: BitArray)
  BeAuthenticationGSS
  BeAuthenticationGSSContinue(auth_data: BitArray)
  BeAuthenticationSSPI
  BeAuthenticationSASL(mechanisms: List(String))
  BeAuthenticationSASLContinue(data: BitArray)
  BeAuthenticationSASLFinal(data: BitArray)
  BeReadyForQuery(TransactionStatus)
  BeRowDescriptions(List(RowDescriptionField))
  BeMessageDataRow(List(BitArray))
  BeBackendKeyData(process_id: Int, secret_key: Int)
  BeParameterStatus(name: String, value: String)
  BeCopyResponse(
    direction: CopyDirection,
    overall_format: Format,
    codes: List(Format),
  )
  BeNegotiateProtocolVersion(
    newest_minor: Int,
    unrecognized_options: List(String),
  )
  BeNoData
  BeNoticeResponse(set.Set(ErrorOrNoticeField))
  BeNotificationResponse(
    process_id: Int,
    channel: String,
    payload: String,
  )
  BeParameterDescription(List(Int))
  BeParseComplete
  BePortalSuspended
  BeErrorResponse(set.Set(ErrorOrNoticeField))
}

Constructors

  • BeBindComplete
  • BeCloseComplete
  • BeCommandComplete(Command, Int)
  • BeCopyData(data: BitArray)
  • BeCopyDone
  • BeAuthenticationOk
  • BeAuthenticationKerberosV5
  • BeAuthenticationCleartextPassword
  • BeAuthenticationMD5Password(salt: BitArray)
  • BeAuthenticationGSS
  • BeAuthenticationGSSContinue(auth_data: BitArray)
  • BeAuthenticationSSPI
  • BeAuthenticationSASL(mechanisms: List(String))
  • BeAuthenticationSASLContinue(data: BitArray)
  • BeAuthenticationSASLFinal(data: BitArray)
  • BeReadyForQuery(TransactionStatus)
  • BeRowDescriptions(List(RowDescriptionField))
  • BeMessageDataRow(List(BitArray))
  • BeBackendKeyData(process_id: Int, secret_key: Int)
  • BeParameterStatus(name: String, value: String)
  • BeCopyResponse(
      direction: CopyDirection,
      overall_format: Format,
      codes: List(Format),
    )
  • BeNegotiateProtocolVersion(
      newest_minor: Int,
      unrecognized_options: List(String),
    )
  • BeNoData
  • BeNoticeResponse(set.Set(ErrorOrNoticeField))
  • BeNotificationResponse(
      process_id: Int,
      channel: String,
      payload: String,
    )
  • BeParameterDescription(List(Int))
  • BeParseComplete
  • BePortalSuspended
  • BeErrorResponse(set.Set(ErrorOrNoticeField))
pub type Command {
  Insert
  Delete
  Update
  Merge
  Select
  Move
  Fetch
  Copy
}

Constructors

  • Insert
  • Delete
  • Update
  • Merge
  • Select
  • Move
  • Fetch
  • Copy
pub type Connection {
  Connection(socket: mug.Socket, buffer: BitArray, timeout: Int)
}

Constructors

  • Connection(socket: mug.Socket, buffer: BitArray, timeout: Int)

Direction of a BeCopyResponse

pub type CopyDirection {
  In
  Out
  Both
}

Constructors

  • In
  • Out
  • Both
pub type DataRow {
  DataRow(List(BitArray))
}

Constructors

  • DataRow(List(BitArray))
pub type ErrorOrNoticeField {
  Code(String)
  Detail(String)
  File(String)
  Hint(String)
  Line(String)
  Message(String)
  Position(String)
  Routine(String)
  SeverityLocalized(String)
  Severity(String)
  Where(String)
  Column(String)
  DataType(String)
  Constraint(String)
  InternalPosition(String)
  InternalQuery(String)
  Schema(String)
  Table(String)
  Unknown(key: BitArray, value: String)
}

Constructors

  • Code(String)
  • Detail(String)
  • File(String)
  • Hint(String)
  • Line(String)
  • Message(String)
  • Position(String)
  • Routine(String)
  • SeverityLocalized(String)
  • Severity(String)
  • Where(String)
  • Column(String)
  • DataType(String)
  • Constraint(String)
  • InternalPosition(String)
  • InternalQuery(String)
  • Schema(String)
  • Table(String)
  • Unknown(key: BitArray, value: String)
pub type FeAmbigous {
  FeGssResponse(data: BitArray)
  FeSaslInitialResponse(name: String, data: BitArray)
  FeSaslResponse(data: BitArray)
  FePasswordMessage(password: String)
}

Constructors

  • FeGssResponse(data: BitArray)
  • FeSaslInitialResponse(name: String, data: BitArray)
  • FeSaslResponse(data: BitArray)
  • FePasswordMessage(password: String)

Indicates encoding of column values

pub type Format {
  Text
  Binary
}

Constructors

  • Text
  • Binary

Lists of parameters can have different encodings.

pub type FormatValue {
  FormatAllText
  FormatAll(Format)
  Formats(List(Format))
}

Constructors

  • FormatAllText
  • FormatAll(Format)
  • Formats(List(Format))
pub type FrontendMessage {
  FeBind(
    portal: String,
    statement_name: String,
    parameter_format: FormatValue,
    parameters: ParameterValues,
    result_format: FormatValue,
  )
  FeCancelRequest(process_id: Int, secret_key: Int)
  FeClose(what: What, name: String)
  FeCopyData(data: BitArray)
  FeCopyDone
  FeCopyFail(error: String)
  FeDescribe(what: What, name: String)
  FeExecute(portal: String, return_row_count: Int)
  FeFlush
  FeFunctionCall(
    object_id: Int,
    argument_format: FormatValue,
    arguments: ParameterValues,
    result_format: Format,
  )
  FeGssEncRequest
  FeParse(
    name: String,
    query: String,
    parameter_object_ids: List(Int),
  )
  FeQuery(query: String)
  FeStartupMessage(params: List(#(String, String)))
  FeSslRequest
  FeTerminate
  FeSync
  FeAmbigous(FeAmbigous)
}

Constructors

  • FeBind(
      portal: String,
      statement_name: String,
      parameter_format: FormatValue,
      parameters: ParameterValues,
      result_format: FormatValue,
    )
  • FeCancelRequest(process_id: Int, secret_key: Int)
  • FeClose(what: What, name: String)
  • FeCopyData(data: BitArray)
  • FeCopyDone
  • FeCopyFail(error: String)
  • FeDescribe(what: What, name: String)
  • FeExecute(portal: String, return_row_count: Int)
  • FeFlush
  • FeFunctionCall(
      object_id: Int,
      argument_format: FormatValue,
      arguments: ParameterValues,
      result_format: Format,
    )
  • FeGssEncRequest
  • FeParse(
      name: String,
      query: String,
      parameter_object_ids: List(Int),
    )
  • FeQuery(query: String)
  • FeStartupMessage(params: List(#(String, String)))
  • FeSslRequest
  • FeTerminate
  • FeSync
  • FeAmbigous(FeAmbigous)
pub type MessageDecodingError {
  MessageDecodingError(String)
  MessageIncomplete(BitArray)
  UnknownMessage(data: BitArray)
}

Constructors

  • MessageDecodingError(String)
  • MessageIncomplete(BitArray)
  • UnknownMessage(data: BitArray)
pub type ParameterValue {
  Parameter(BitArray)
  Null
}

Constructors

  • Parameter(BitArray)
  • Null
pub type ParameterValues =
  List(ParameterValue)
pub type ReadError {
  SocketError(mug.Error)
  ReadDecodeError(MessageDecodingError)
}

Constructors

  • SocketError(mug.Error)
  • ReadDecodeError(MessageDecodingError)
pub type RowDescriptionField {
  RowDescriptionField(
    name: String,
    table_oid: Int,
    attr_number: Int,
    data_type_oid: Int,
    data_type_size: Int,
    type_modifier: Int,
    format_code: Int,
  )
}

Constructors

  • RowDescriptionField(
      name: String,
      table_oid: Int,
      attr_number: Int,
      data_type_oid: Int,
      data_type_size: Int,
      type_modifier: Int,
      format_code: Int,
    )
pub type StartupFailed {
  StartupFailedWithUnexpectedMessage(BackendMessage)
  StartupFailedWithError(ReadError)
}

Constructors

  • StartupFailedWithUnexpectedMessage(BackendMessage)
  • StartupFailedWithError(ReadError)
pub type State {
  State(
    process_id: Int,
    secret_key: Int,
    parameters: dict.Dict(String, String),
    oids: dict.Dict(Int, fn(BitArray) -> Result(Int, Nil)),
  )
}

Constructors

  • State(
      process_id: Int,
      secret_key: Int,
      parameters: dict.Dict(String, String),
      oids: dict.Dict(Int, fn(BitArray) -> Result(Int, Nil)),
    )
pub type StateInitial {
  StateInitial(parameters: dict.Dict(String, String))
}

Constructors

  • StateInitial(parameters: dict.Dict(String, String))
pub type TransactionStatus {
  TransactionStatusIdle
  TransactionStatusInTransaction
  TransactionStatusFailed
}

Constructors

  • TransactionStatusIdle
  • TransactionStatusInTransaction
  • TransactionStatusFailed
pub type What {
  PreparedStatement
  Portal
}

Constructors

  • PreparedStatement
  • Portal

Constants

pub const protocol_version: BitArray = <<
  protocol_version_major:bits,
  protocol_version_minor:bits,
>>
pub const protocol_version_major: BitArray = <<3:16>>
pub const protocol_version_minor: BitArray = <<0:16>>

Functions

pub fn connect(
  host: String,
  port: Int,
  timeout: Int,
) -> Connection
pub fn decode_backend_message(
  binary: BitArray,
) -> Result(BackendMessage, MessageDecodingError)
pub fn decode_backend_packet(
  packet: BitArray,
) -> Result(#(BackendMessage, BitArray), MessageDecodingError)
pub fn decode_frontend_message(
  binary: BitArray,
) -> Result(FrontendMessage, MessageDecodingError)

decode a frontend message (also see decode_frontend_packet for messages that can’t be decoded here)

pub fn decode_frontend_packet(
  packet: BitArray,
) -> Result(#(FrontendMessage, BitArray), MessageDecodingError)

decode a single message from the packet buffer. note that FeCancelRequest, FeSslRequest, FeGssEncRequest, and FeStartupMessage messages can only be decoded here because they don’t follow the standard message format.

pub fn encode_backend_message(
  message: BackendMessage,
) -> BitArray
pub fn encode_frontend_message(
  message: FrontendMessage,
) -> BitArray
pub fn receive(
  conn: Connection,
) -> Result(#(Connection, BackendMessage), ReadError)

Receive a single message from the backend

pub fn send(
  conn: Connection,
  message: BitArray,
) -> Result(Connection, Error)

Send a message to the database

pub fn send_builder(
  conn: Connection,
  message: BytesBuilder,
) -> Result(Connection, Error)

Send a message to the database

pub fn start(
  conn: Connection,
  params: List(#(String, String)),
) -> #(Connection, State)
Search Document