ChannelSession

Struct ChannelSession 

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

A channel-based session for message-passing style communication

Implementations§

Source§

impl ChannelSession

Source

pub fn command( &self, rql: &str, params: Option<Params>, ) -> Result<String, Box<dyn Error>>

Send a command (response arrives on channel)

Examples found in repository?
examples/channel_ws.rs (line 27)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9	// Connect to ReifyDB server
10	let client = Client::ws(("127.0.0.1", 8090))?;
11
12	// Create a channel session with authentication
13	let (session, receiver) = client.channel_session(Some("mysecrettoken".to_string()))?;
14
15	// Consume authentication response
16	if let Ok(msg) = receiver.recv_timeout(Duration::from_millis(100)) {
17		if let Ok(ChannelResponse::Auth {
18			request_id,
19		}) = msg.response
20		{
21			println!("Authenticated with ID: {}", request_id);
22		}
23	}
24
25	// Execute a command to create a table
26	let command_id =
27		session.command("CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }", None)?;
28	println!("Command sent with ID: {}", command_id);
29
30	// Execute a query
31	let query_id = session.query("MAP { x: 42, y: 'hello' }", None)?;
32	println!("Query sent with ID: {}", query_id);
33
34	// Receive responses
35	let mut received = 0;
36	while received < 2 {
37		match receiver.recv_timeout(Duration::from_secs(1)) {
38			Ok(msg) => {
39				match msg.response {
40					Ok(ChannelResponse::Command {
41						request_id,
42						result,
43					}) => {
44						println!(
45							"Command {} executed: {} frames returned",
46							request_id,
47							result.frames.len()
48						);
49						received += 1;
50					}
51					Ok(ChannelResponse::Query {
52						request_id,
53						result,
54					}) => {
55						println!(
56							"Query {} executed: {} frames returned",
57							request_id,
58							result.frames.len()
59						);
60						// Print first frame if
61						// available
62						if let Some(frame) = result.frames.first() {
63							println!("First frame:\n{}", frame);
64						}
65						received += 1;
66					}
67					Ok(ChannelResponse::Auth {
68						..
69					}) => {
70						// Already handled above
71					}
72					Err(e) => {
73						println!("Request {} failed: {}", msg.request_id, e);
74						received += 1;
75					}
76				}
77			}
78			Err(_) => {
79				println!("Timeout waiting for responses");
80				break;
81			}
82		}
83	}
84
85	Ok(())
86}
Source

pub fn query( &self, rql: &str, params: Option<Params>, ) -> Result<String, Box<dyn Error>>

Send a query (response arrives on channel)

Examples found in repository?
examples/channel_ws.rs (line 31)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9	// Connect to ReifyDB server
10	let client = Client::ws(("127.0.0.1", 8090))?;
11
12	// Create a channel session with authentication
13	let (session, receiver) = client.channel_session(Some("mysecrettoken".to_string()))?;
14
15	// Consume authentication response
16	if let Ok(msg) = receiver.recv_timeout(Duration::from_millis(100)) {
17		if let Ok(ChannelResponse::Auth {
18			request_id,
19		}) = msg.response
20		{
21			println!("Authenticated with ID: {}", request_id);
22		}
23	}
24
25	// Execute a command to create a table
26	let command_id =
27		session.command("CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }", None)?;
28	println!("Command sent with ID: {}", command_id);
29
30	// Execute a query
31	let query_id = session.query("MAP { x: 42, y: 'hello' }", None)?;
32	println!("Query sent with ID: {}", query_id);
33
34	// Receive responses
35	let mut received = 0;
36	while received < 2 {
37		match receiver.recv_timeout(Duration::from_secs(1)) {
38			Ok(msg) => {
39				match msg.response {
40					Ok(ChannelResponse::Command {
41						request_id,
42						result,
43					}) => {
44						println!(
45							"Command {} executed: {} frames returned",
46							request_id,
47							result.frames.len()
48						);
49						received += 1;
50					}
51					Ok(ChannelResponse::Query {
52						request_id,
53						result,
54					}) => {
55						println!(
56							"Query {} executed: {} frames returned",
57							request_id,
58							result.frames.len()
59						);
60						// Print first frame if
61						// available
62						if let Some(frame) = result.frames.first() {
63							println!("First frame:\n{}", frame);
64						}
65						received += 1;
66					}
67					Ok(ChannelResponse::Auth {
68						..
69					}) => {
70						// Already handled above
71					}
72					Err(e) => {
73						println!("Request {} failed: {}", msg.request_id, e);
74						received += 1;
75					}
76				}
77			}
78			Err(_) => {
79				println!("Timeout waiting for responses");
80				break;
81			}
82		}
83	}
84
85	Ok(())
86}

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, 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, 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.