pub struct BlockingSession { /* private fields */ }Expand description
A blocking session that waits for responses synchronously
Implementations§
Source§impl BlockingSession
impl BlockingSession
Sourcepub fn command(
&mut self,
rql: &str,
params: Option<Params>,
) -> Result<CommandResult, Error>
pub fn command( &mut self, rql: &str, params: Option<Params>, ) -> Result<CommandResult, Error>
Send a command and wait for response
Examples found in repository?
examples/blocking_ws.rs (line 16)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 // Connect to ReifyDB server - various ways to specify address:
8 // Using tuple (address, port):
9 let client = Client::ws(("127.0.0.1", 8090))?;
10
11 // Create a blocking session with authentication
12 let mut session = client.blocking_session(Some("mysecrettoken".to_string()))?;
13
14 // Execute a command to create a table
15 let command_result =
16 session.command("CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }", None)?;
17 println!("Command executed: {} frames returned", command_result.frames.len());
18
19 // Execute a query
20 let query_result = session.query("MAP { x: 42, y: 'hello' }", None)?;
21
22 println!("Query executed: {} frames returned", query_result.frames.len());
23
24 // Print first frame if available
25 if let Some(frame) = query_result.frames.first() {
26 println!("First frame:\n{}", frame);
27 }
28
29 Ok(())
30}Sourcepub fn query(
&mut self,
rql: &str,
params: Option<Params>,
) -> Result<QueryResult, Error>
pub fn query( &mut self, rql: &str, params: Option<Params>, ) -> Result<QueryResult, Error>
Send a query and wait for response
Examples found in repository?
examples/blocking_ws.rs (line 20)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 // Connect to ReifyDB server - various ways to specify address:
8 // Using tuple (address, port):
9 let client = Client::ws(("127.0.0.1", 8090))?;
10
11 // Create a blocking session with authentication
12 let mut session = client.blocking_session(Some("mysecrettoken".to_string()))?;
13
14 // Execute a command to create a table
15 let command_result =
16 session.command("CREATE NAMESPACE test; CREATE TABLE test.users { id: INT4, name: UTF8 }", None)?;
17 println!("Command executed: {} frames returned", command_result.frames.len());
18
19 // Execute a query
20 let query_result = session.query("MAP { x: 42, y: 'hello' }", None)?;
21
22 println!("Query executed: {} frames returned", query_result.frames.len());
23
24 // Print first frame if available
25 if let Some(frame) = query_result.frames.first() {
26 println!("First frame:\n{}", frame);
27 }
28
29 Ok(())
30}More examples
examples/test_remote_sort.rs (line 33)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 println!("Connecting to ws://192.168.100.52:8090/\n");
6
7 // Connect to the remote server
8 let client = Client::ws(("192.168.100.52", 8090))?;
9
10 // Try with auth token from environment or use "root"
11 let token = std::env::var("REIFYDB_TOKEN").unwrap_or_else(|_| "root".to_string());
12 println!(
13 "Using auth token: {}\n",
14 if token == "root" {
15 "root (default)"
16 } else {
17 &token
18 }
19 );
20
21 // Create a blocking session with auth token
22 let mut session = client.blocking_session(Some(token))?;
23
24 println!("Connected successfully!\n");
25
26 // Test ASC
27 println!("=== TEST 1: ASC (should show smallest first) ===");
28 println!("Query:");
29 println!("from system.table_storage_stats");
30 println!("sort total_bytes asc\n");
31
32 let query_asc = "from system.table_storage_stats\nsort total_bytes asc";
33 let result_asc = session.query(query_asc, None)?;
34
35 if let Some(frame) = result_asc.frames.first() {
36 if let Some(total_bytes_col) = frame.columns.iter().find(|c| c.name == "total_bytes") {
37 let mut values: Vec<u64> = Vec::new();
38 for i in 0..total_bytes_col.data.len() {
39 let val = total_bytes_col.data.as_string(i).parse::<u64>().unwrap_or(0);
40 values.push(val);
41 }
42 println!("ASC Results: {:?}", values);
43 println!("First value (should be smallest): {}", values[0]);
44 println!("Last value (should be largest): {}\n", values[values.len() - 1]);
45 }
46 }
47
48 // Test DESC
49 println!("=== TEST 2: DESC (should show largest first) ===");
50 println!("Query:");
51 println!("from system.table_storage_stats");
52 println!("sort total_bytes desc\n");
53
54 let query = "from system.table_storage_stats\nsort total_bytes desc";
55 let result = session.query(query, None)?;
56
57 println!("Query executed: {} frames returned\n", result.frames.len());
58
59 // Print the results
60 if let Some(frame) = result.frames.first() {
61 println!("Frame output:");
62 println!("{}\n", frame);
63
64 // Also analyze the data
65 if let Some(total_bytes_col) = frame.columns.iter().find(|c| c.name == "total_bytes") {
66 println!("=== Analyzing total_bytes column ===");
67 let mut values: Vec<u64> = Vec::new();
68 for i in 0..total_bytes_col.data.len() {
69 let val = total_bytes_col.data.as_string(i).parse::<u64>().unwrap_or(0);
70 values.push(val);
71 println!("Row {}: {} bytes", i, val);
72 }
73
74 println!("\nValues in order: {:?}", values);
75
76 // Check if sorted correctly (DESC = largest first)
77 let mut is_desc_sorted = true;
78 for i in 1..values.len() {
79 if values[i - 1] < values[i] {
80 is_desc_sorted = false;
81 println!(
82 "\n⚠️ SORTING ERROR at position {}: {} < {}",
83 i,
84 values[i - 1],
85 values[i]
86 );
87 }
88 }
89
90 if is_desc_sorted {
91 println!("\n✅ Correctly sorted in DESCENDING order (largest first)");
92 } else {
93 println!("\n❌ NOT correctly sorted in descending order!");
94 println!(" Expected: Largest value first, decreasing values");
95 println!(" Got: {:?}", values);
96 }
97 }
98 }
99
100 Ok(())
101}Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if the session is authenticated
Auto Trait Implementations§
impl Freeze for BlockingSession
impl RefUnwindSafe for BlockingSession
impl Send for BlockingSession
impl !Sync for BlockingSession
impl Unpin for BlockingSession
impl UnwindSafe for BlockingSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more