pub struct GrpcConnection { /* private fields */ }Expand description
A gRPC connection to a Hyper database (query-only).
Unlike Connection, this provides read-only access via gRPC
with results in Apache Arrow IPC format. This is useful for:
- Load-balanced deployments where gRPC provides better routing
- Integration with Arrow-based data pipelines
- Scenarios where HTTP/2 benefits are needed
§Limitations
gRPC connections only support SELECT queries. Attempting to execute DDL (CREATE, DROP), DML (INSERT, UPDATE, DELETE), or use features like prepared statements will result in an error.
§Async vs Sync
This struct provides both async and sync APIs:
connect()/execute_query()- blocking (uses internal tokio runtime)connect_async()/execute_query_async()- async (requires tokio runtime)
For applications already using tokio, the async methods are preferred.
Implementations§
Source§impl GrpcConnection
impl GrpcConnection
Sourcepub fn connect(endpoint: &str, database_path: &str) -> Result<Self>
pub fn connect(endpoint: &str, database_path: &str) -> Result<Self>
Connects to a Hyper server via gRPC (blocking).
§Arguments
endpoint- The gRPC endpoint URL (e.g., “http://localhost:7484”)database_path- Path to the database to query
§Example
let conn = GrpcConnection::connect(
"http://localhost:7484",
"my_database.hyper"
)?;§Errors
Returns crate::Error::Client wrapping a
hyperdb_api_core::client::Error if the HTTP/2 channel cannot be established
(endpoint unreachable, TLS handshake failure, auth rejection).
Sourcepub fn connect_with_config(config: GrpcConfig) -> Result<Self>
pub fn connect_with_config(config: GrpcConfig) -> Result<Self>
Connects to a Hyper server via gRPC with custom configuration (blocking).
§Example
let config = GrpcConfig::new("http://localhost:7484")
.database("my_database.hyper")
.connect_timeout(Duration::from_secs(10))
.header("x-custom-header", "value");
let conn = GrpcConnection::connect_with_config(config)?;§Errors
Returns crate::Error::Client if the HTTP/2 channel cannot be
established with the supplied configuration.
Sourcepub fn execute_query_to_arrow(&mut self, sql: &str) -> Result<Bytes>
pub fn execute_query_to_arrow(&mut self, sql: &str) -> Result<Bytes>
Executes a SQL query and returns raw Arrow IPC bytes (blocking).
This is the most efficient method when you need the raw Arrow data for processing with an Arrow library.
§Example
let arrow_bytes = conn.execute_query_to_arrow("SELECT * FROM users")?;
// Process with arrow crate using the zero-copy helper
let rowset = hyperdb_api::ArrowRowset::from_bytes(arrow_bytes)?;§Errors
Returns crate::Error::Client if the gRPC server rejects the query
or if the HTTP/2 channel fails mid-stream.
Sourcepub fn execute_query(&mut self, sql: &str) -> Result<GrpcQueryResult>
pub fn execute_query(&mut self, sql: &str) -> Result<GrpcQueryResult>
Executes a SQL query and returns a structured result (blocking).
The result contains the Arrow IPC data along with metadata about the query execution.
§Example
let result = conn.execute_query("SELECT id, name FROM users")?;
println!("Query ID: {:?}", result.query_id());
println!("Columns: {}", result.column_count());
let arrow_data = result.into_arrow_data();§Errors
Returns crate::Error::Client if the gRPC server rejects the query
or the HTTP/2 channel fails.
Sourcepub fn cancel_query(&mut self, query_id: &str) -> Result<()>
pub fn cancel_query(&mut self, query_id: &str) -> Result<()>
Cancels an in-flight gRPC query by its query_id (blocking).
This is the gRPC analogue of PG wire’s CancelRequest. Unlike PG
wire — where the cancel opens a separate TCP connection — the
gRPC cancel rides the existing HTTP/2 channel as a regular RPC,
so it reuses this connection’s channel, database routing, and
custom headers.
§When you have a query_id
The server assigns a query_id for ASYNC-mode queries
(long-running queries that the client polls). Read it from
GrpcQueryResult::query_id after an async-mode execution.
SYNC-mode queries typically complete before a cancel would be
useful — drop the in-flight future instead.
Cancellation is best-effort: a successful Ok(()) return means
the server acknowledged the cancel, not that the query had not
already finished. Errors indicate a transport-level failure
(channel closed, network error, auth expired) — useful for
metrics, retry logic, or “cancel failed” UX.
§Fallible by design
The Result<()> return is the explicit user-facing cancel
API and is distinct from the
Cancellable trait, which requires
an infallible cancel(&self) method with no arguments. A
GrpcConnection cannot implement Cancellable directly: the
trait’s signature has nowhere to pass a query_id, and gRPC
connections can carry many concurrent queries (so there is no
unambiguous “the” query to cancel the way there is on a PG wire
connection). If you need Cancellable-style fire-and-forget
cancel for a future gRPC streaming result type, it will live
on a per-query handle that wraps this method and swallows
errors — mirroring
impl Cancellable for hyperdb_api_core::client::Client.
§Example
conn.cancel_query(query_id)?;§Errors
Returns crate::Error::Client on transport-level failures (channel
closed, network error, auth expired). An unknown or already-finished
query_id is not an error — the server returns Ok.
Sourcepub fn config(&self) -> &GrpcConfig
pub fn config(&self) -> &GrpcConfig
Returns the gRPC configuration.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GrpcConnection
impl !RefUnwindSafe for GrpcConnection
impl Send for GrpcConnection
impl Sync for GrpcConnection
impl Unpin for GrpcConnection
impl UnsafeUnpin for GrpcConnection
impl !UnwindSafe for GrpcConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request