Skip to main content

FraiseClient

Struct FraiseClient 

Source
pub struct FraiseClient { /* private fields */ }
Expand description

FraiseQL wire protocol client

Implementations§

Source§

impl FraiseClient

Source

pub async fn connect(connection_string: &str) -> Result<Self>

Connect to Postgres using connection string

§Examples
use fraiseql_wire::FraiseClient;

// TCP connection
let client = FraiseClient::connect("postgres://localhost/mydb").await?;

// Unix socket
let client = FraiseClient::connect("postgres:///mydb").await?;
Source

pub async fn connect_tls( connection_string: &str, tls_config: TlsConfig, ) -> Result<Self>

Connect to Postgres with TLS encryption

TLS is configured independently from the connection string. The connection string should contain the hostname and credentials (user/password), while TLS configuration is provided separately via TlsConfig.

§Examples
use fraiseql_wire::{FraiseClient, connection::TlsConfig};

// Configure TLS with system root certificates
let tls = TlsConfig::builder()
    .verify_hostname(true)
    .build()?;

// Connect with TLS
let client = FraiseClient::connect_tls("postgres://secure.db.example.com/mydb", tls).await?;
Source

pub async fn connect_with_config( connection_string: &str, config: ConnectionConfig, ) -> Result<Self>

Connect to Postgres with custom connection configuration

This method allows you to configure timeouts, keepalive intervals, and other connection options. The connection configuration is merged with parameters from the connection string.

§Examples
use fraiseql_wire::{FraiseClient, connection::ConnectionConfig};
use std::time::Duration;

// Build connection configuration with timeouts
let config = ConnectionConfig::builder("localhost", "mydb")
    .password("secret")
    .statement_timeout(Duration::from_secs(30))
    .keepalive_idle(Duration::from_secs(300))
    .application_name("my_app")
    .build();

// Connect with configuration
let client = FraiseClient::connect_with_config("postgres://localhost:5432/mydb", config).await?;
Source

pub async fn connect_with_config_and_tls( connection_string: &str, config: ConnectionConfig, tls_config: TlsConfig, ) -> Result<Self>

Connect to Postgres with both custom configuration and TLS encryption

This method combines connection configuration (timeouts, keepalive, etc.) with TLS encryption for secure connections with advanced options.

§Examples
use fraiseql_wire::{FraiseClient, connection::{ConnectionConfig, TlsConfig}};
use std::time::Duration;

// Configure connection with timeouts
let config = ConnectionConfig::builder("localhost", "mydb")
    .password("secret")
    .statement_timeout(Duration::from_secs(30))
    .build();

// Configure TLS
let tls = TlsConfig::builder()
    .verify_hostname(true)
    .build()?;

// Connect with both configuration and TLS
let client = FraiseClient::connect_with_config_and_tls(
    "postgres://secure.db.example.com/mydb",
    config,
    tls
).await?;
Source

pub fn query<T: DeserializeOwned + Unpin + 'static>( self, entity: impl Into<String>, ) -> QueryBuilder<T>

Start building a query for an entity with automatic deserialization

The type parameter T controls consumer-side deserialization only. Type T does NOT affect SQL generation, filtering, ordering, or wire protocol.

§Examples

Type-safe query (recommended):

use serde::Deserialize;
use futures::stream::StreamExt;

#[derive(Deserialize)]
struct User {
    id: String,
    name: String,
}

let mut stream = client
    .query::<User>("user")
    .where_sql("data->>'type' = 'customer'")  // SQL predicate
    .where_rust(|json| {
        // Rust predicate (applied client-side, on JSON)
        json["estimated_value"].as_f64().unwrap_or(0.0) > 1000.0
    })
    .order_by("data->>'name' ASC")
    .execute()
    .await?;

while let Some(result) = stream.next().await {
    let user: User = result?;
    println!("User: {}", user.name);
}

Raw JSON query (debugging, forward compatibility):

use futures::stream::StreamExt;

let mut stream = client
    .query::<serde_json::Value>("user")  // Escape hatch
    .execute()
    .await?;

while let Some(result) = stream.next().await {
    let json = result?;
    println!("JSON: {:?}", json);
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more