module PG::Frontend
The messages a client sends, encoded as the server reads them. Each
function returns the whole message, framed (PG::Wire.frame).
Constants
PROTOCOL: Int
Protocol 3.0, as the startup message names it.
SSL_REQUEST: Int
The code an SSLRequest sends in place of a protocol version.
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"
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"
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"
def self.sasl_initial_response(mechanism: String, data: Bytes?) -> Bytes
The first SASL message: the mechanism chosen and its first data (nil: none).
def self.sasl_response(data: Bytes) -> Bytes
A later SASL message.
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"
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).
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.
def self.describe_statement(name: String) -> Bytes
Asks for a prepared statement's parameter types and row shape.
def self.describe_portal(name: String) -> Bytes
Asks for a portal's row shape.
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.
def self.close_statement(name: String) -> Bytes
Closes a prepared statement.
def self.close_portal(name: String) -> Bytes
Closes a portal.
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"
def self.flush -> Bytes
Asks the server to send what it has buffered.
def self.terminate -> Bytes
Ends the session.