pub struct Connection { /* private fields */ }Expand description
Postgres connection
Implementations§
Source§impl Connection
impl Connection
Sourcepub const fn state(&self) -> ConnectionState
pub const fn state(&self) -> ConnectionState
Get current connection state
Sourcepub async fn startup(&mut self, config: &ConnectionConfig) -> Result<()>
pub async fn startup(&mut self, config: &ConnectionConfig) -> Result<()>
Perform startup and authentication
§Errors
Returns WireError::InvalidState if the connection is not in the Initial state.
Returns WireError::Authentication if authentication is rejected by the server.
Returns WireError on any I/O or protocol error during the handshake.
Sourcepub async fn simple_query(&mut self, query: &str) -> Result<Vec<BackendMessage>>
pub async fn simple_query(&mut self, query: &str) -> Result<Vec<BackendMessage>>
Execute a simple query (returns all backend messages)
§Errors
Returns WireError::ConnectionBusy if the connection is not idle.
Returns WireError::InvalidState if the state machine transition fails.
Returns WireError on any I/O or protocol error during execution.
Sourcepub async fn close(self) -> Result<()>
pub async fn close(self) -> Result<()>
Close the connection
§Errors
Returns WireError::InvalidState if the state machine transition to Closed fails.
Returns WireError if the transport shutdown fails.
Sourcepub async fn streaming_query(
self,
query: &str,
chunk_size: usize,
max_memory: Option<usize>,
soft_limit_warn_threshold: Option<f32>,
soft_limit_fail_threshold: Option<f32>,
enable_adaptive_chunking: bool,
adaptive_min_chunk_size: Option<usize>,
adaptive_max_chunk_size: Option<usize>,
) -> Result<JsonStream>
pub async fn streaming_query( self, query: &str, chunk_size: usize, max_memory: Option<usize>, soft_limit_warn_threshold: Option<f32>, soft_limit_fail_threshold: Option<f32>, enable_adaptive_chunking: bool, adaptive_min_chunk_size: Option<usize>, adaptive_max_chunk_size: Option<usize>, ) -> Result<JsonStream>
Execute a streaming query
Note: This method consumes the connection. The stream maintains the connection internally. Once the stream is exhausted or dropped, the connection is closed.
§Errors
Returns WireError::Io if sending the query or reading the response fails.
Returns WireError::Database if the server returns an error response.
Returns WireError::InvalidSchema if the row description is not a single JSON column.