thingdom / node-neo4j

[RETIRED] Neo4j graph database driver (REST API client) for Node.js
Apache License 2.0
925 stars 135 forks source link

In the doc of transaction, can I use results from makeFirstQuery() in makeSecondQuery() 's params? #195

Closed linonetwo closed 8 years ago

linonetwo commented 8 years ago

in transaction it reads:

function makeFirstQuery() {
    tx.cypher({
        query: '...',
        params {...},
    }, makeSecondQuery);
}

function makeSecondQuery(err, results) {
    if (err) throw err;
    // ...some application logic...
    tx.cypher({
        query: '...',
        params: {...},
    }, finish);
}

function finish(err, results) {
    if (err) throw err;
    // ...some application logic...
    tx.commit(done);  // or tx.rollback(done);
}

function done(err) {
    if (err) throw err;
    // At this point, the transaction has been committed.
}

can I use results from makeFirstQuery() in makeSecondQuery() 's params?

And what does done() used for? It doesn't receive a results parameter.

aseemk commented 8 years ago

Hi @linonetwo,

can I use results from makeFirstQuery() in makeSecondQuery() 's params?

Absolutely!

And what does done() used for? It doesn't receive a results parameter.

done is just the callback for tx.commit. tx.commit (and tx.rollback) callbacks don't receive any results. They're just a way for you to know whether the commit (or rollback) was successful. E.g. you might want to wait for this before responding to a request.

Hope this helps! Feel free to ask any more q's.