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 Error::InvalidState if the connection is not in the initial state.
Returns Error::Authentication if authentication fails.
Returns Error::Io if sending or receiving protocol messages fails.
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 Error::ConnectionBusy if the connection is not idle.
Returns Error::InvalidState if a state transition is invalid.
Returns Error::Io if sending or receiving protocol messages fails.
Sourcepub async fn close(self) -> Result<()>
pub async fn close(self) -> Result<()>
Close the connection
§Errors
Returns Error::InvalidState if the connection cannot transition to closed.
Returns Error::Io 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 Error::ConnectionBusy if the connection is not idle.
Returns Error::InvalidState if a state transition is invalid.
Returns Error::Sql if the database returns an error response.
Returns Error::Protocol if the query produces no result set or an unexpected message.
Returns Error::InvalidSchema if the row description does not match requirements.
Returns Error::Io if sending or receiving protocol messages fails.