Expand description
Rust client for UDB — a proto-driven gRPC broker over multiple databases.
use udb_client::{Metadata, UdbClient};
let meta = Metadata::new("tenant-1")
.with_project("default")
.with_bearer_token(std::env::var("UDB_TOKEN")?);
let mut udb = UdbClient::connect("http://127.0.0.1:50051", meta).await?;
let set = udb
.select(udb_client::proto::udb::entity::v1::SelectRequest {
message_type: "myapp.v1.Invoice".into(),
..Default::default()
})
.await?;
// `records_json` is the canonical representation; `set.rows` is a
// compatibility field the broker sends EMPTY. Decode, never index `rows`.
for record in udb_client::Records::decode(&set)?.iter() {
println!("{}", record.str("id")?);
}§Two listeners, two authorization models
UDB serves its data plane and its native services on SEPARATE listeners with
DIFFERENT authorization models — the data plane authorizes through Casbin,
the native services through scope-based endpoint security. A credential
accepted by one is not automatically accepted by the other, and the mismatch
surfaces as a permissions error rather than a wrong-address error. UdbClient
speaks to the data plane.
§Generated types
The stubs under proto are generated at build time from the protos rather
than committed, so this crate cannot drift from the contract it ships with.
They are laid out by proto package: udb.entity.v1 is
proto::udb::entity::v1.
Re-exports§
pub use auth::exchange_token_for_job;pub use auth::DelegatedJobToken;pub use auth::ExchangeTokenForJobRequest;pub use auth::Token;pub use auth::TokenManager;pub use client::SelectError;pub use client::UdbClient;pub use error::CallPolicy;pub use error::UdbError;pub use generated_rpcs::is_retry_safe;pub use generated_rpcs::spec_for_path;pub use generated_rpcs::RpcSpec;pub use metadata::Metadata;pub use record::DecodeError;pub use record::Record;pub use record::Records;pub use prost;pub use prost_types;pub use serde_json;pub use tonic;
Modules§
- auth
- Login and the token lifecycle.
- client
- The data-plane client.
- error
- Typed errors and retry policy.
- generated_
rpcs - The RPC registry generated from the proto descriptor set.
- metadata
- The request metadata every UDB call carries.
- proto
- Generated protobuf and tonic client types, nested by proto package.
- record
- Decoding relational reads.
Constants§
- FILE_
DESCRIPTOR_ SET - The whole UDB contract as an encoded
google.protobuf.FileDescriptorSet: every service, request and response type the typed clients underprotowere generated from. For callers that build requests at runtime (a reflection-driven tool, a benchmark over every RPC) with a descriptor library such asprost-reflect.