laminas / laminas-db

Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations
https://docs.laminas.dev/laminas-db/
BSD 3-Clause "New" or "Revised" License
119 stars 66 forks source link

Support for read-only transactions #310

Open lalande21185 opened 4 weeks ago

lalande21185 commented 4 weeks ago

RFC

Add support for read only transactions. Currently you can start a transaction with beginTransaction. The proposal would add a beginReadOnlyTransaction method that starts a read-only transaction.

Q A
Proposed Version 2.21.0
BC Break? No

Goal

Provide a method to start a read-only transaction. The proposed name for the method is beginReadOnlyTransaction.

Background

I experienced a use case where I needed a read-only transaction. While it is easy enough to do it with the existing library. We can make it easier with a ready-to-use method that is well tested.

Considerations

There is no required preparation for laminas-db users. The change does not break anything.

Proposal(s)

Users will use the method beginReadOnlyTransaction when wanting to start a read-only transaction. Everything else stays the same.

Appendix

First, add the method beginReadOnlyTransaction to Laminas\Db\Adapter\Driver\ConnectionInterface. Then implement the method in each driver. Finally, make sure the new code is covered with tests.

I welcome all questions and feedback on the proposal.

Ocramius commented 4 weeks ago

This hugely depends on the backend, so it can't be implemented in a generic way, AFAIK.

lalande21185 commented 4 weeks ago

I see it supports MySQL, SQLite, Oracle, Sql Server, PostgreSQL and IBM Db2. My understanding is that as long as transactions are supported, then read-only transactions are supported for each database. So if you can do beginTransaction you should be able to do something like beginReadOnlyTransaction.

I cannot be sure yet without trying. I could give it a go and if it just does not work, then I leave it.