Skip to main content

Client

Struct Client 

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

API to tarantool.

Create client by call build() on ClientConfig.

§Examples

let client = ClientConfig::new(addr, “rust”, “rust”).set_timeout_time_ms(1000).set_reconnect_time_ms(10000).build();

Implementations§

Source§

impl Client

Source

pub fn new(config: ClientConfig) -> Client

manually create client by consume Client Config

Source

pub fn prepare_sql<T>(&self, sql: T) -> PreparedSql
where T: Into<String>,

prepare sql call

§Examples

rust code

    let response : TarantoolSqlResponse<(u32, String)> = client
        .prepare_sql("select * from TABLE1 where COLUMN1=?")
        .bind(&1)?
        .execute().await?;
    let rows = response.decode_result_set()?;
Source

pub fn prepare_fn_call<T>(&self, function_name: T) -> PreparedFunctionCall
where T: Into<String>,

prepare call to stored procedure

§Examples

rust code

let response = client
        .prepare_fn_call("test")
        .bind(&("aa", "aa"))?
        .bind(&1)?
        .execute().await?;
    let s: (Vec<String>, u64) = response.decode_pair()?;
Source

pub fn get_status(&self) -> ClientStatus

return client status

Source

pub fn subscribe_to_notify_stream(&self) -> UnboundedReceiver<ClientStatus>

return notify stream with connection statuses

Source

pub async fn send_command( &self, req: CommandPacket, ) -> Result<TarantoolResponse>

send any command you manually create, this method is low level and not intended to be used

Source

pub async fn call_fn<T>( &self, function: &str, params: &T, ) -> Result<TarantoolResponse>
where T: Serialize,

call tarantool stored procedure

params mast be serializable to MsgPack tuple by Serde - rust tuple or vector or struct (by default structs serialized as tuple)

order of fields in serializes tuple is order of parameters of procedure

§Examples

lua function on tarantool

function test(a,b)
  return a,b,11
 end

rust code

 let response = client.call_fn("test", &(("aa", "aa"), 1)).await?;
 let s: (Vec<String>, Vec<u64>) = response.decode_pair()?;
 println!("resp value={:?}", s);
 assert_eq!((vec!["aa".to_string(), "aa".to_string()], vec![1]), s);
Source

pub async fn call_fn1<T1>( &self, function: &str, param1: &T1, ) -> Result<TarantoolResponse>
where T1: Serialize,

call tarantool stored procedure with one parameter

Source

pub async fn call_fn2<T1, T2>( &self, function: &str, param1: &T1, param2: &T2, ) -> Result<TarantoolResponse>
where T1: Serialize, T2: Serialize,

call tarantool stored procedure with two parameters

§Examples
 let response = client.call_fn2("test", &("param11", "param12") , &2).await?;
  let s: (Vec<String>, Vec<u64>) = response.decode_pair()?;
  println!("resp value={:?}", s);
  assert_eq!((vec!["aa".to_string(), "aa".to_string()], vec![1]), s);
Source

pub async fn call_fn3<T1, T2, T3>( &self, function: &str, param1: &T1, param2: &T2, param3: &T3, ) -> Result<TarantoolResponse>
where T1: Serialize, T2: Serialize, T3: Serialize,

call tarantool stored procedure with three parameters

Source

pub async fn call_fn4<T1, T2, T3, T4>( &self, function: &str, param1: &T1, param2: &T2, param3: &T3, param4: &T4, ) -> Result<TarantoolResponse>
where T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize,

call tarantool stored procedure with four parameters

Source

pub async fn call_fn5<T1, T2, T3, T4, T5>( &self, function: &str, param1: &T1, param2: &T2, param3: &T3, param4: &T4, param5: &T5, ) -> Result<TarantoolResponse>
where T1: Serialize, T2: Serialize, T3: Serialize, T4: Serialize, T5: Serialize,

call tarantool stored procedure with five parameters

Source

pub async fn select<T>( &self, space: i32, index: i32, key: &T, offset: i32, limit: i32, iterator: IteratorType, ) -> Result<TarantoolResponse>
where T: Serialize,

call “select” from tarantool

  • space - i32 space id
  • index - i32 index id
  • key - key part used for select, may be sequence (vec or tuple)
  • offset - i32 select offset
  • limit - i32 limit of rows
  • iterator - type of iterator
Source

pub async fn insert<T>( &self, space: i32, tuple: &T, ) -> Result<TarantoolResponse>
where T: Serialize,

insert tuple to space

  • space - space id
  • tuple - sequence of fields(can be vec or rust tuple)
Source

pub async fn replace<T>( &self, space: i32, tuple: &T, ) -> Result<TarantoolResponse>
where T: Serialize,

replace tuple in space by primary key

  • space - space id
  • tuple - sequence of fields(can be vec or rust tuple)
§Examples
let tuple_replace= (3,"test_insert","replace");
client.replace(SPACE_ID, &tuple_replace).await?;
Source

pub async fn replace_raw( &self, space: i32, tuple_raw: Vec<u8>, ) -> Result<TarantoolResponse>

replace tuple in space by primary key - raw method if you have already serialized msgpack

  • space - space id
  • tuple - sequence of fields stored as msgpack
§Examples
let tuple_replace= (3,"test_insert","replace");
let raw_buf = serialize_to_vec_u8(&tuple_replace).unwrap();
client.replace_raw(SPACE_ID, raw_buf).await?;
Source

pub async fn update<T, T2>( &self, space: i32, key: &T2, args: &T, ) -> Result<TarantoolResponse>
where T: Serialize, T2: Serialize,

update row in tarantool

  • space - space id
  • key - sequence of fields(rust tuple or vec)
  • args - sequence of update operations, for example ((‘=’,2,“test_update”),)
§Examples
let tuple= (3,"test_insert");
let update_op= (('=',2,"test_update"),);
client.update(SPACE_ID, &tuple, &update_op).await?;
Source

pub async fn upsert<T, T2, T3>( &self, space: i32, key: &T2, def: &T3, args: &T, ) -> Result<TarantoolResponse>
where T: Serialize, T2: Serialize, T3: Serialize,

upsert row in tuple

§Examples
let key= (4,"test_upsert");
let update_op= (('=',2,"test_update_upsert"),);
client.upsert(SPACE_ID,&key, &key,&update_op).await?;
Source

pub async fn delete<T>(&self, space: i32, key: &T) -> Result<TarantoolResponse>
where T: Serialize,

delete row in space

§Examples
let tuple= (3,"test_insert");
client.delete(SPACE_ID,&tuple).await?;
Source

pub async fn eval<T, T1>( &self, expression: T1, args: &T, ) -> Result<TarantoolResponse>
where T: Serialize, T1: Into<String>,

eval expression in tarantool

§Examples
client.eval("return ...\n".to_string(),&(1,2)).await?
Source

pub async fn exec_sql<T, T1>( &self, sql: T1, args: &T, ) -> Result<TarantoolResponse>
where T: Serialize, T1: Into<String>,

eval sql expression in tarantool

§Examples
client.exec_sql("select * from TABLE1 where COLUMN1=?".to_string(), &(1,)).await?;
Source

pub async fn ping(&self) -> Result<TarantoolResponse>

ping tarantool server, return empty response in success

§Examples
client.ping().await?

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.