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

CREATE statement does nothing if the result isn't iterated #112

Open
rick-carpool opened this issue Sep 12, 2023 · 1 comment
Open

CREATE statement does nothing if the result isn't iterated #112

rick-carpool opened this issue Sep 12, 2023 · 1 comment

Comments

@rick-carpool
Copy link

version: 0.6.2

client.execute(query("create (n:MyNode {p: 'prop})")).await.unwrap();

returns with no error but also does nothing.

let mut result = client.execute(query("create (n:MyNode {p: 'prop})")).await.unwrap();
while let Ok(Some(row)) = result.next().await {}

writes to the db as expected.

@knutwalker
Copy link
Collaborator

That behavior is by design, basically. Bolt is a stateful protocol and calling execute will return a RowStream that is in the READY state.

At this point, the server has parsed and validated the query, produced a plan and returned the result schema to the client. It is ready to produce results, but it's waiting for the client to be told to do so, which will happen on the first call to next. This streaming happens in chunks (config.fetch_size) and looping through all the calls to next ensures that all of those chunks are requested and executed on the server.

If you want to run a query for its side effects, you should use run instead of execute.
I am also adding must_use to RowStream, which would at least give you a warning:

warning: unused `RowStream` that must be used
  --> lib/tests/result_stream.rs:27:5
   |
27 | /     graph
28 | |         .execute(query("CREATE (n:MyNode {p: 'prop'})"))
29 | |         .await
30 | |         .unwrap();
   | |_________________^
   |
   = note: Results must be streamed through with `next` in order to execute the query
   = note: `#[warn(unused_must_use)]` on by default

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

No branches or pull requests

2 participants