Skip to main content

Client

Struct Client 

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

KeystoneDB remote client

Implementations§

Source§

impl Client

Source

pub async fn connect(addr: impl Into<String>) -> Result<Self>

Connect to a KeystoneDB server

§Arguments
  • addr - Server address (e.g., “http://127.0.0.1:50051”)
§Example
let client = Client::connect("http://localhost:50051").await?;
Source

pub async fn put(&mut self, pk: &[u8], item: Item) -> Result<()>

Put an item with a simple partition key

§Arguments
  • pk - Partition key
  • item - Item to store
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let mut item = HashMap::new();
item.insert("name".to_string(), Value::S("Alice".to_string()));
item.insert("age".to_string(), Value::N("30".to_string()));

client.put(b"user#123", item).await?;
Source

pub async fn put_with_sk( &mut self, pk: &[u8], sk: &[u8], item: Item, ) -> Result<()>

Put an item with partition key and sort key

§Arguments
  • pk - Partition key
  • sk - Sort key
  • item - Item to store
Source

pub async fn put_conditional( &mut self, pk: &[u8], item: Item, condition: impl Into<String>, values: HashMap<String, Value>, ) -> Result<()>

Put an item with a condition expression

§Arguments
  • pk - Partition key
  • item - Item to store
  • condition - Condition expression (e.g., “attribute_not_exists(pk)”)
  • values - Expression attribute values
Source

pub async fn get(&mut self, pk: &[u8]) -> Result<Option<Item>>

Get an item with a simple partition key

§Arguments
  • pk - Partition key
§Returns

The item if found, None otherwise

Source

pub async fn get_with_sk( &mut self, pk: &[u8], sk: &[u8], ) -> Result<Option<Item>>

Get an item with partition key and sort key

§Arguments
  • pk - Partition key
  • sk - Sort key
§Returns

The item if found, None otherwise

Source

pub async fn delete(&mut self, pk: &[u8]) -> Result<()>

Delete an item with a simple partition key

§Arguments
  • pk - Partition key
Source

pub async fn delete_with_sk(&mut self, pk: &[u8], sk: &[u8]) -> Result<()>

Delete an item with partition key and sort key

§Arguments
  • pk - Partition key
  • sk - Sort key
Source

pub async fn delete_conditional( &mut self, pk: &[u8], condition: impl Into<String>, values: HashMap<String, Value>, ) -> Result<()>

Delete an item with a condition expression

§Arguments
  • pk - Partition key
  • condition - Condition expression (e.g., “attribute_exists(pk)”)
  • values - Expression attribute values
Source

pub async fn query(&mut self, query: RemoteQuery) -> Result<RemoteQueryResponse>

Execute a query operation

§Arguments
  • query - Query builder with conditions
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let query = RemoteQuery::new(b"user#org1")
    .sk_begins_with(b"USER#")
    .limit(10);

let response = client.query(query).await?;
println!("Found {} items", response.count);
Source

pub async fn scan(&mut self, scan: RemoteScan) -> Result<RemoteScanResponse>

Execute a scan operation

§Arguments
  • scan - Scan builder with options
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let scan = RemoteScan::new()
    .limit(100);

let response = client.scan(scan).await?;
println!("Scanned {} items", response.count);
Source

pub async fn batch_get( &mut self, request: RemoteBatchGetRequest, ) -> Result<RemoteBatchGetResponse>

Execute a batch get operation

§Arguments
  • request - Batch get request with keys
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let batch = RemoteBatchGetRequest::new()
    .add_key(b"user#1")
    .add_key(b"user#2");

let response = client.batch_get(batch).await?;
println!("Retrieved {} items", response.count);
Source

pub async fn batch_write( &mut self, request: RemoteBatchWriteRequest, ) -> Result<RemoteBatchWriteResponse>

Execute a batch write operation

§Arguments
  • request - Batch write request with puts/deletes
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let mut item = HashMap::new();
item.insert("name".to_string(), Value::S("Alice".to_string()));

let batch = RemoteBatchWriteRequest::new()
    .put(b"user#1", item.clone())
    .delete(b"user#old");

let response = client.batch_write(batch).await?;
println!("Batch write success: {}", response.success);
Source

pub async fn transact_get( &mut self, request: RemoteTransactGetRequest, ) -> Result<RemoteTransactGetResponse>

Execute a transactional get operation

§Arguments
  • request - TransactGet request with keys to retrieve
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let request = RemoteTransactGetRequest::new()
    .get(b"user#1")
    .get(b"user#2");

let response = client.transact_get(request).await?;
println!("Retrieved {} items", response.items.len());
Source

pub async fn transact_write( &mut self, request: RemoteTransactWriteRequest, ) -> Result<()>

Execute a transactional write operation

§Arguments
  • request - TransactWrite request with operations
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let mut item = HashMap::new();
item.insert("name".to_string(), Value::S("Alice".to_string()));

let request = RemoteTransactWriteRequest::new()
    .put(b"user#1", item);

client.transact_write(request).await?;
Source

pub async fn update( &mut self, request: RemoteUpdate, ) -> Result<RemoteUpdateResponse>

Update an item using update expression

§Arguments
  • request - Update request with expression
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let update = RemoteUpdate::new(b"user#1")
    .expression("SET age = age + :inc")
    .value(":inc", Value::N("1".to_string()));

let response = client.update(update).await?;
println!("Updated item: {:?}", response.item);
Source

pub async fn execute_statement( &mut self, statement: impl Into<String>, ) -> Result<RemoteExecuteStatementResponse>

Execute a PartiQL statement

§Arguments
  • statement - PartiQL SQL statement
§Example
let mut client = Client::connect("http://localhost:50051").await?;

let response = client.execute_statement(
    "SELECT * FROM users WHERE pk = 'user#123'"
).await?;

println!("Query result: {:?}", response);

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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 = !

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

fn try_from(value: U) -> Result<T, !>

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