pub struct PgwireLite { /* private fields */ }Expand description
Main client for interacting with PostgreSQL-compatible servers.
This struct provides the core functionality for establishing connections and executing queries against a PostgreSQL-compatible server.
Implementations§
Source§impl PgwireLite
impl PgwireLite
Sourcepub fn new(
hostname: &str,
port: u16,
use_tls: bool,
verbosity: &str,
) -> Result<Self, Box<dyn Error>>
pub fn new( hostname: &str, port: u16, use_tls: bool, verbosity: &str, ) -> Result<Self, Box<dyn Error>>
Creates a new PgwireLite client with the specified connection parameters.
§Arguments
hostname- The hostname or IP address of the PostgreSQL serverport- The port number the PostgreSQL server is listening onuse_tls- Whether to use TLS encryption for the connectionverbosity- Error/notice verbosity level, one of: “terse”, “default”, “verbose”, “sqlstate”
§Returns
A Result containing the new PgwireLite instance or an error
§Example
use pgwire_lite::PgwireLite;
let client = PgwireLite::new("localhost", 5432, false, "default")
.expect("Failed to create client");Sourcepub fn libpq_version(&self) -> String
pub fn libpq_version(&self) -> String
Returns the version of the underlying libpq library.
§Returns
A string representing the version in the format “major.minor.patch”
Sourcepub fn verbosity(&self) -> String
pub fn verbosity(&self) -> String
Returns the current verbosity setting.
§Returns
A string representation of the current verbosity level
Sourcepub fn query(&self, query: &str) -> Result<QueryResult, Box<dyn Error>>
pub fn query(&self, query: &str) -> Result<QueryResult, Box<dyn Error>>
Executes a SQL query and returns the results.
This method creates a fresh connection for each query, executes the query, and processes the results. It handles all aspects of connection management and error handling.
§Arguments
query- The SQL query to execute
§Returns
A Result containing a QueryResult with the query results or an error
§Example
use pgwire_lite::PgwireLite;
let client = PgwireLite::new("localhost", 5444, false, "default")
.expect("Failed to create client");
let result = client.query("SELECT 1 as value")
.expect("Query failed");
println!("Number of rows: {}", result.row_count);