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

Differentiate results across queries in a transaction #9

Closed
aseemk opened this issue Nov 6, 2014 · 7 comments
Closed

Differentiate results across queries in a transaction #9

aseemk opened this issue Nov 6, 2014 · 7 comments

Comments

@aseemk
Copy link
Collaborator

aseemk commented Nov 6, 2014

Hey @brian-gates, I'm working on thingdom/node-neo4j#143 now, specifically the design of the transactional API that'd wrap this guy. =)

Thinking about a need / use case we at @fiftythree have in our own app, one thing we'd need is the ability to differentiate results across the various queries that make up a transaction.

AFAICT right now, the current cypher-stream design doesn't differentiate. A transaction is a single stream of results, with data events that don't tell you which query (statement) each result corresponds to.

For example, if the caller doesn't know in advance how many results a query will give, they don't know when the results for one query ends and the next begins.

What are your thoughts for how to achieve that?

@aseemk
Copy link
Collaborator Author

aseemk commented Nov 6, 2014

One way I can think of to achieve this is to have the main TransactionStream actually return individual CypherStreams. Each query (write) into the transaction stream yields a corresponding results stream out of the transaction stream.

If it's important, maybe there could be an option to "flatten" the result streams into the outer transaction stream, which would get you today's current behavior.

@brian-gates
Copy link
Contributor

I was just talking with @wfreeman about this :)

It's totally doable, and a feature I plan to add in the near future.

You pretty much described the API I had in mind:

var transaction = cypher.transaction();
transaction.write({ 
  statement : 'match (n) return n limit 1', 
  callback  : function (stream) { // CypherStream
    stream.on('data', function(result) {
      console.log(result.n); 
    })
  }
});
transaction.commit()

I was also thinking of an idea of a transaction 'channel', which is a factory that automatically manages the creation and committing of transactions for you.

The idea being that you can group queries together that don't conflict transactionally and just blast it with queries and it would manage the batching for you automatically.

This would allow an application to batch queries even from separate concurrent requests transparently.

var transaction = cypher.transaction({ channel: 'create-comments' });
transaction.write({
  statement : createCommentsQuery,
  callback  : handleCreatedComment(s),
})
// will batch all 'create-comments' queries together and auto-commit the transaction after a certain debounce period or max-duration

@aseemk
Copy link
Collaborator Author

aseemk commented Nov 6, 2014

Sweet. Looking forward to it! =)

P.S. Have you considered making e.g. a gitter.im chatroom for this repo? It's like IRC but much, much better. =)

@freeeve
Copy link

freeeve commented Nov 6, 2014

I think anyone can make the chatroom. See you there...

@aseemk
Copy link
Collaborator Author

aseemk commented Nov 6, 2014

I tried actually and didn't seem to be able to, but I could've easily been doing something wrong...

@brian-gates
Copy link
Contributor

@brian-gates
Copy link
Contributor

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

3 participants