Skip to content

Commit

Permalink
Sync versions are much cleaner now
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyMatt committed May 28, 2024
1 parent 1f87290 commit bbb682f
Show file tree
Hide file tree
Showing 17 changed files with 416 additions and 505 deletions.
16 changes: 6 additions & 10 deletions src/client/asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*/

use crate::{
client::FalkorClientProvider, connection::asynchronous::BorrowedAsyncConnection, AsyncGraph,
AsyncGraphSchema, ConfigValue, FalkorAsyncConnection, FalkorConnectionInfo, FalkorDBError,
client::FalkorClientProvider, connection::asynchronous::BorrowedAsyncConnection,
parser::utils::string_vec_from_val, AsyncGraph, AsyncGraphSchema, ConfigValue,
FalkorAsyncConnection, FalkorConnectionInfo, FalkorDBError,
};
use anyhow::Result;
use std::{
Expand Down Expand Up @@ -100,14 +101,9 @@ impl FalkorAsyncClient {
/// A [`Vec`] of [`String`]s, containing the names of available graphs
pub async fn list_graphs(&self) -> Result<Vec<String>> {
let mut conn = self.borrow_connection().await?;

Ok(conn
.send_command(None, "GRAPH.LIST", None, None)
.await?
.into_vec()?
.into_iter()
.flat_map(|data| data.into_string())
.collect::<Vec<_>>())
conn.send_command(None, "GRAPH.LIST", None, None)
.await
.and_then(|res| string_vec_from_val(res).map_err(Into::into))
}

/// Return the current value of a configuration option in the database.
Expand Down
16 changes: 6 additions & 10 deletions src/client/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the Server Side Public License v1 (SSPLv1).
*/

use crate::parser::utils::string_vec_from_val;
use crate::{
client::FalkorClientProvider,
connection::blocking::{BorrowedSyncConnection, FalkorSyncConnection},
Expand Down Expand Up @@ -84,13 +85,8 @@ impl FalkorSyncClient {
/// A [`Vec`] of [`String`]s, containing the names of available graphs
pub fn list_graphs(&self) -> Result<Vec<String>> {
let mut conn = self.borrow_connection()?;

let graph_list = conn.send_command::<&str>(None, "GRAPH.LIST", None, None)?;
Ok(graph_list
.into_vec()?
.into_iter()
.flat_map(|name| name.into_string())
.collect())
conn.send_command::<&str>(None, "GRAPH.LIST", None, None)
.and_then(|res| string_vec_from_val(res).map_err(Into::into))
}

/// Return the current value of a configuration option in the database.
Expand Down Expand Up @@ -248,7 +244,7 @@ mod tests {
.query("MATCH (a:actor) return a".to_string())
.expect("Could not get actors from unmodified graph");

assert_eq!(res.result_set.len(), 1317);
assert_eq!(res.data.len(), 1317);
}

#[test]
Expand All @@ -271,11 +267,11 @@ mod tests {
.inner
.query("MATCH (a:actor) RETURN a".to_string())
.expect("Could not get actors from unmodified graph")
.result_set,
.data,
original_graph
.query("MATCH (a:actor) RETURN a".to_string())
.expect("Could not get actors from unmodified graph")
.result_set
.data
)
}

Expand Down
11 changes: 3 additions & 8 deletions src/graph/asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ impl AsyncGraph {

let mut slowlog_entries = Vec::with_capacity(res.len());
for entry_raw in res {
slowlog_entries.push(SlowlogEntry::from_value_array(
entry_raw
.into_vec()?
.try_into()
.map_err(|_| FalkorDBError::ParsingArrayToStructElementCount)?,
)?);
slowlog_entries.push(SlowlogEntry::from_value_vec(entry_raw.into_vec()?)?);
}

Ok(slowlog_entries)
Expand Down Expand Up @@ -320,7 +315,7 @@ impl AsyncGraph {
/// A [`Vec`] of [`Index`]
pub async fn list_indices(&self) -> Result<Vec<FalkorIndex>> {
let mut conn = self.client.borrow_connection().await?;
let [_, indices, _]: [FalkorValue; 3] = self
let [header, indices, stats]: [FalkorValue; 3] = self
.call_procedure::<&str, FalkorValue>("DB.INDEXES", None, None, false, None)
.await?
.into_vec()?
Expand Down Expand Up @@ -429,7 +424,7 @@ impl AsyncGraph {
/// A [`Vec`] of [`Constraint`]s
pub async fn list_constraints(&self) -> Result<Vec<Constraint>> {
let mut conn = self.client.borrow_connection().await?;
let [_, query_res, _]: [FalkorValue; 3] = self
let [header, query_res, stats]: [FalkorValue; 3] = self
.call_procedure::<&str, FalkorValue>("DB.CONSTRAINTS", None, None, false, None)
.await?
.into_vec()?
Expand Down
Loading

0 comments on commit bbb682f

Please sign in to comment.