postgleam/connection
Types
Connection state
pub type ConnectionState {
ConnectionState(
transport: @internal Transport,
connection_id: option.Option(Int),
connection_key: option.Option(Int),
parameters: dict.Dict(String, String),
transaction_status: message.TransactionStatus,
buffer: BitArray,
)
}
Constructors
-
ConnectionState( transport: @internal Transport, connection_id: option.Option(Int), connection_key: option.Option(Int), parameters: dict.Dict(String, String), transaction_status: message.TransactionStatus, buffer: BitArray, )
Result from an extended query execution
pub type ExtendedQueryResult {
ExtendedQueryResult(
tag: String,
columns: List(message.RowField),
rows: List(List(option.Option(value.Value))),
)
}
Constructors
-
ExtendedQueryResult( tag: String, columns: List(message.RowField), rows: List(List(option.Option(value.Value))), )
A prepared statement returned by prepare
pub type PreparedStatement {
PreparedStatement(
name: String,
statement: String,
param_oids: List(Int),
result_fields: List(message.RowField),
)
}
Constructors
-
PreparedStatement( name: String, statement: String, param_oids: List(Int), result_fields: List(message.RowField), )
Result from a simple query
pub type SimpleQueryResult {
SimpleQueryResult(
tag: String,
columns: List(String),
rows: List(List(option.Option(String))),
)
}
Constructors
-
SimpleQueryResult( tag: String, columns: List(String), rows: List(List(option.Option(String))), )
Result of a streamed execute - either more rows available or done
pub type StreamChunk {
StreamMore(rows: List(List(option.Option(value.Value))))
StreamDone(
tag: String,
rows: List(List(option.Option(value.Value))),
)
}
Constructors
-
StreamMore(rows: List(List(option.Option(value.Value))))More rows available, call execute_portal again
-
StreamDone( tag: String, rows: List(List(option.Option(value.Value))), )All rows received, includes the command tag
Values
pub fn bind_and_execute_portal(
state: ConnectionState,
prepared: PreparedStatement,
params: List(option.Option(value.Value)),
registry: dict.Dict(Int, codec.Codec),
max_rows: Int,
timeout: Int,
) -> Result(#(StreamChunk, ConnectionState), error.Error)
Bind parameters and execute first chunk: Bind + Execute(max_rows) + Flush Uses Flush instead of Sync to keep the unnamed portal alive. Returns the first chunk of rows.
pub fn close_statement(
state: ConnectionState,
name: String,
timeout: Int,
) -> Result(ConnectionState, error.Error)
Close a prepared statement: Close + Sync
pub fn connect(
config: config.Config,
) -> Result(ConnectionState, error.Error)
Establish a connection to PostgreSQL, complete authentication, and return ready state
pub fn execute_portal(
state: ConnectionState,
prepared: PreparedStatement,
registry: dict.Dict(Int, codec.Codec),
max_rows: Int,
timeout: Int,
) -> Result(#(StreamChunk, ConnectionState), error.Error)
Execute the next chunk from a portal: Execute(max_rows) + Flush Returns StreamMore if portal is suspended (more rows), StreamDone if complete.
pub fn execute_prepared(
state: ConnectionState,
prepared: PreparedStatement,
params: List(option.Option(value.Value)),
registry: dict.Dict(Int, codec.Codec),
timeout: Int,
) -> Result(#(ExtendedQueryResult, ConnectionState), error.Error)
Execute a prepared statement with binary parameters: Bind + Execute + Sync Parameters are encoded using the codec registry.
pub fn extended_query(
state: ConnectionState,
sql: String,
params: List(option.Option(value.Value)),
registry: dict.Dict(Int, codec.Codec),
timeout: Int,
) -> Result(#(ExtendedQueryResult, ConnectionState), error.Error)
All-in-one extended query: Parse + Describe + Bind + Execute + Close + Sync Uses unnamed statement and portal for simplicity.
pub fn prepare(
state: ConnectionState,
name: String,
sql: String,
type_oids: List(Int),
timeout: Int,
) -> Result(#(PreparedStatement, ConnectionState), error.Error)
Prepare a statement: Parse + Describe + Sync Returns the prepared statement with parameter and result type info.
pub fn receive_message(
state: ConnectionState,
timeout: Int,
) -> Result(
#(message.BackendMessage, ConnectionState),
error.Error,
)
Receive and decode the next backend message
pub fn send_bytes(
state: ConnectionState,
bytes: BitArray,
) -> Result(ConnectionState, error.Error)
Send raw bytes over the transport
pub fn send_message(
state: ConnectionState,
msg: message.FrontendMessage,
) -> Result(ConnectionState, error.Error)
Send a frontend message over the transport
pub fn simple_query(
state: ConnectionState,
sql: String,
timeout: Int,
) -> Result(
#(List(SimpleQueryResult), ConnectionState),
error.Error,
)
Execute a simple query (text protocol) and return all results
pub fn sync_portal(
state: ConnectionState,
timeout: Int,
) -> Result(ConnectionState, error.Error)
Finalize portal streaming: Sync to get ReadyForQuery