Skip to content

Commit

Permalink
Simplify result summary api (#222)
Browse files Browse the repository at this point in the history
* Simplify result stream by removing the RowOrSummary enum

The result summary can now only be returned from `finish`, which also consumes the stream.
The next_or_summary and *_items_* methods are removed.
This also simplifies the API for finish, the summary no longer has to be returned as an option.
Before it could have already been returned by a call to next_or_summary, which would result in a None being returned from finish.
Having the API like that is also closer to APIs from the product drivers

* Remove RowItem
  • Loading branch information
knutwalker authored Feb 12, 2025
1 parent 5d9e84e commit c2b733d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 268 deletions.
39 changes: 6 additions & 33 deletions lib/include/result_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,18 @@
}

//
// next_or_summary
// next + finish

let mut stream = graph
.execute(query("CREATE (n:Node {prop: 'frobnicate'}) RETURN n"))
.await
.unwrap();

let Ok(Some(row)) = stream.next_or_summary().await else { panic!() };
assert!(row.row().is_some());
assert!(row.summary().is_none());
let Ok(Some(row)) = stream.next().await else { panic!() };
assert_item(row.to().unwrap());

assert_item(row.row().unwrap().to().unwrap());

let Ok(Some(row)) = stream.next_or_summary().await else { panic!() };
assert!(row.row().is_none());
assert!(row.summary().is_some());

assert_summary(row.summary().unwrap());


//
// as_items

let mut stream = graph
.execute(query("CREATE (n:Node {prop: 'frobnicate'}) RETURN n"))
.await
.unwrap();

let items = stream.as_items::<N>()
.try_collect::<Vec<_>>()
.await
.unwrap();

for item in items {
match item {
RowItem::Row(row) => assert_item(row),
RowItem::Summary(summary) => assert_summary(&summary),
}
}
let Ok(summary) = stream.finish().await else { panic!() };
assert_summary(&summary);


//
Expand All @@ -76,7 +49,7 @@
.await
.unwrap();

let Ok(Some(summary)) = stream.finish().await else { panic!() };
let Ok(summary) = stream.finish().await else { panic!() };

for item in items {
assert_item(item);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ pub use crate::errors::{
pub use crate::graph::{query, Graph};
pub use crate::query::{Query, QueryParameter};
pub use crate::row::{Node, Path, Point2D, Point3D, Relation, Row, UnboundedRelation};
pub use crate::stream::{DetachedRowStream, RowItem, RowStream};
pub use crate::stream::{DetachedRowStream, RowStream};
pub use crate::txn::Txn;
pub use crate::types::serde::{
DeError, EndNodeId, Id, Indices, Keys, Labels, Nodes, Offset, Relationships, StartNodeId,
Expand Down
Loading

0 comments on commit c2b733d

Please sign in to comment.