Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make result summary available behind a feature flag #199

Merged
merged 14 commits into from
Sep 4, 2024

Conversation

knutwalker
Copy link
Collaborator

@knutwalker knutwalker commented Sep 4, 2024

With this change it is possible to access to result summary of a query by enabling the unstable-v1 feature:

use neo4rs::*;
use neo4rs::summary::{Type, Counters, ResultSummary};

#[derive(Debug, PartialEq, serde::Deserialize)]
struct Person {
    name: String,
}

async fn example() -> Result<()> {
    let uri = "127.0.0.1:7687";
    let user = "neo4j";
    let pass = "password";
    let graph = Graph::new(uri, user, pass).await?;
    
    let mut stream = graph
        .execute(query("CREATE (n:Person {name: 'Alice'}) RETURN n"))
        .await?;

    let people = stream.into_stream_as::<Person>()
        .try_collect::<Vec<_>>()
        .await?;

    for person in people {
        assert_eq!(person.name, "Alice");
    }

    let Some(summary) = stream.finish().await? else { panic!("no summary available") };
    let summary: ResultSummary = summary; // The type of the summary

    assert!(summary.available_after().is_some());
    assert!(summary.consumed_after().is_some());
    assert!(summary.db().is_some());
    assert_eq!(summary.query_type(), Type::ReadWrite);
    assert_eq!(summary.stats(), &Counters {
        nodes_created: 1,
        properties_set: 1,
        labels_added: 1,
        ..Default::default()
    });
}

The API is behind an unstable feature flag, so it might change before it is available without a feature flag.

@jexp
Copy link

jexp commented Sep 4, 2024

Nice 👍🏼

@knutwalker knutwalker changed the title Make result summary available Make result summary available behind a feature flag Sep 4, 2024
@knutwalker knutwalker enabled auto-merge (squash) September 4, 2024 20:30
@knutwalker knutwalker merged commit a7a20d5 into main Sep 4, 2024
10 checks passed
@knutwalker knutwalker deleted the streaming-summary branch September 4, 2024 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants