module PG::Frontend

The messages a client sends, encoded as the server reads them. Each function returns the whole message, framed (PG::Wire.frame).

src/frontend.qz:3

Constants

PROTOCOL: Int

Protocol 3.0, as the startup message names it.

src/frontend.qz:5

SSL_REQUEST: Int

The code an SSLRequest sends in place of a protocol version.

src/frontend.qz:8

Class methods

def self.ssl_request -> Bytes

The SSLRequest: asks the server, before the startup message, whether it speaks TLS; it answers one byte, S or N.

PG::Frontend.ssl_request.hex   # => "0000000804d2162f"

src/frontend.qz:16

def self.startup(params: Hash[String, String]) -> Bytes

The startup message: the protocol version and the parameters (user is required; database, client_encoding, application_name, ...), in the order given.

PG::Frontend.startup({ "user" => "u" }).hex   # => "00000010000300007573657200750000"

src/frontend.qz:25

def self.password(text: String) -> Bytes

A password, in clear or as md5 auth hashes it (the protocol's PasswordMessage).

PG::Frontend.password("pw")   # => b"p\x00\x00\x00\x07pw\x00"

src/frontend.qz:40

def self.sasl_initial_response(mechanism: String, data: Bytes?) -> Bytes

The first SASL message: the mechanism chosen and its first data (nil: none).

src/frontend.qz:46

def self.sasl_response(data: Bytes) -> Bytes

A later SASL message.

src/frontend.qz:58

def self.query(sql: String) -> Bytes

A simple query: one or several statements, run at once.

PG::Frontend.query("select 1")   # => b"Q\x00\x00\x00\rselect 1\x00"

src/frontend.qz:65

def self.parse(name: String, sql: String, types: Array[Int] = …) -> Bytes

Parses sql into the prepared statement name ("": the unnamed one); types gives the OIDs of the first parameters (0, or none: the server infers them).

src/frontend.qz:72

def self.bind(portal: String, statement: String, params: Array[Bytes?]) -> Bytes

Binds params (each in text format, or nil for NULL) to the prepared statement statement, making the portal portal; the results come in text format.

src/frontend.qz:83

def self.describe_statement(name: String) -> Bytes

Asks for a prepared statement's parameter types and row shape.

src/frontend.qz:101

def self.describe_portal(name: String) -> Bytes

Asks for a portal's row shape.

src/frontend.qz:104

def self.execute(portal: String, max_rows: Int = …) -> Bytes

Runs the portal, returning at most max_rows rows (0: all of them). Raises ArgumentError when max_rows is negative or beyond 2^31 - 1.

src/frontend.qz:108

def self.close_statement(name: String) -> Bytes

Closes a prepared statement.

src/frontend.qz:116

def self.close_portal(name: String) -> Bytes

Closes a portal.

src/frontend.qz:119

def self.sync -> Bytes

Ends an extended query: the server answers ReadyForQuery, after an error too.

PG::Frontend.sync   # => b"S\x00\x00\x00\x04"

src/frontend.qz:127

def self.flush -> Bytes

Asks the server to send what it has buffered.

src/frontend.qz:130

def self.terminate -> Bytes

Ends the session.

src/frontend.qz:133