neo4j-go-driver
neo4j-go-driver copied to clipboard
Support for "automatic transaction" management like spring boot
I believe it would be interesting to have support for more "automatic" handling of transactions, just writing a transaction manager while creating my application, I would like to know if I can contribute a PR.
example:
// where *T is your possible returned value
txManager := neo4jdb.WithTransaction[T](driver)
_, err := txManager(currentCtx, func(transactionCtx context.Context) (*T, error) {
// execute your custom service logic in transaction
})
this would be great
Hello @rullyalves!
Thank you very much for your suggestion, and our apologies for not replying in a more timely manner. Larger features like this are ones we generally prefer all of the core drivers (Go, .Net, JavaScript, Python and Java) to implement together and with a unified design. I will add this to the agenda of a meeting this week, and we'll get back to you regarding the transaction manager!
The team has had a discussion on this and decided that this is not something that we are likely to implement in the short to medium term. Our reasoning is that 1) It ideally requires two phase commit and Neo4j does not support this. It would require considerable time from many teams through out the tech stack. 2) There is not a JTA like framework in the Go ecosystem for it to integrate into.
Hi, i dont understand "It ideally requires two phase commit and Neo4j does not support this", can you explain for me ? As far as I know, this involves starting a transaction, performing operations using the transaction object, and then committing or canceling it.
It might be that we misunderstood the question.
Perhaps we were too literal in thinking about what you meant by referring to JTS as an example. We approached the question working on the basis that JTS is a way to run a group of processes as a single transaction, for instance if you want to run queries against Neo4j and another DB as one unit of work that needs to commit or rollback as one. To do this it uses a two phase commit, it 'prepares' the queries for running and once they all return success it tells the dbs to actually run them and do the commit. In Neo4j we do it in a single commit phase, without the prepare part. To enable the use of JTS (or something similar in GO) the driver would implement the interface so it could plug into the framework.
If you are talking more about running a unit of 'work' within a transaction, e.g. several dependent queries interleaved with application code, then you can achieve this using the drivers transaction functions ExecuteRead and ExecuteWrite https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/neo4j#ExecuteRead