pub struct CallbackSession { /* private fields */ }Expand description
A callback-based session for asynchronous operations
Implementations§
Source§impl CallbackSession
impl CallbackSession
Sourcepub fn command<F>(
&self,
rql: &str,
params: Option<Params>,
callback: F,
) -> Result<String, Error>
pub fn command<F>( &self, rql: &str, params: Option<Params>, callback: F, ) -> Result<String, Error>
Send a command with callback
Examples found in repository?
examples/callback_ws.rs (lines 16-23)
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 callback session with authentication
13 let session = client.callback_session(Some("mysecrettoken".to_string()))?;
14
15 // Execute a command to create a table
16 let command_id = session.command(
17 "CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }",
18 None,
19 |result| match result {
20 Ok(data) => println!("Command executed: {} frames returned", data.frames.len()),
21 Err(e) => println!("Command failed: {}", e),
22 },
23 )?;
24 println!("Command sent with ID: {}", command_id);
25
26 // Execute a query
27 let query_id = session.query("MAP { x: 42, y: 'hello' }", None, |result| {
28 match result {
29 Ok(data) => {
30 println!("Query executed: {} frames returned", data.frames.len());
31 // Print first frame if available
32 if let Some(frame) = data.frames.first() {
33 println!("First frame:\n{}", frame);
34 }
35 }
36 Err(e) => println!("Query failed: {}", e),
37 }
38 })?;
39 println!("Query sent with ID: {}", query_id);
40
41 // Wait for callbacks to complete
42 thread::sleep(Duration::from_millis(500));
43
44 Ok(())
45}Sourcepub fn query<F>(
&self,
rql: &str,
params: Option<Params>,
callback: F,
) -> Result<String, Error>
pub fn query<F>( &self, rql: &str, params: Option<Params>, callback: F, ) -> Result<String, Error>
Send a query with callback
Examples found in repository?
examples/callback_ws.rs (lines 27-38)
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 callback session with authentication
13 let session = client.callback_session(Some("mysecrettoken".to_string()))?;
14
15 // Execute a command to create a table
16 let command_id = session.command(
17 "CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }",
18 None,
19 |result| match result {
20 Ok(data) => println!("Command executed: {} frames returned", data.frames.len()),
21 Err(e) => println!("Command failed: {}", e),
22 },
23 )?;
24 println!("Command sent with ID: {}", command_id);
25
26 // Execute a query
27 let query_id = session.query("MAP { x: 42, y: 'hello' }", None, |result| {
28 match result {
29 Ok(data) => {
30 println!("Query executed: {} frames returned", data.frames.len());
31 // Print first frame if available
32 if let Some(frame) = data.frames.first() {
33 println!("First frame:\n{}", frame);
34 }
35 }
36 Err(e) => println!("Query failed: {}", e),
37 }
38 })?;
39 println!("Query sent with ID: {}", query_id);
40
41 // Wait for callbacks to complete
42 thread::sleep(Duration::from_millis(500));
43
44 Ok(())
45}Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if the session is authenticated