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

Transaction isolation #408

Closed
jimmycuadra opened this Issue Aug 18, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@jimmycuadra
Contributor

jimmycuadra commented Aug 18, 2016

Does Diesel allow control of the isolation level of a transaction? It doesn't appear that it does right now, in which case consider this a feature request!

Specifically, for my use case, I want to use the "serializable" transaction isolation level in Postgres for an operation where a transaction should fail if a value it read in a query has changed by the time the transaction is committed. In other words, it queries a table, and if the data returned matches the expected condition, adds a new row to another table, but that insert should fail if the row previously queried from the first table has changed. (If there's a better way to do that, I'm all ears!) In other other words, defending against a time of check to time of use error.

@sgrif

This comment has been minimized.

Member

sgrif commented Aug 18, 2016

So the main question that comes to mind with this feature is what the behavior should be when inside of a nested transaction. I guess the simplest answer would be to not support specifying the isolation level when starting the transaction, and instead just add support for SET TRANSACTION instead.

@jimmycuadra

This comment has been minimized.

Contributor

jimmycuadra commented Sep 14, 2016

Any idea of the timetable for this? Is this a post-1.0 feature? I've got a few things I need it for already.

@jimmycuadra

This comment has been minimized.

Contributor

jimmycuadra commented Sep 14, 2016

Also, it looks like I'm going to need PG's advisory locks. Should I open a separate issue for that, or shall we repurpose this one to cover support for all the various concurrency control mechanisms in PG?

@sgrif

This comment has been minimized.

Member

sgrif commented Sep 16, 2016

Seems like advisory locks can just be done with sql_function!. I'll try to get SET TRANSACTION support in the next release

@sgrif sgrif added this to the 0.8 milestone Sep 16, 2016

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 6, 2016

Taking this off the milestone. It's a relatively minor feature to add, but it's not super critical at the moment, as we don't offer a ton over `execute("SET TRANSACTION WHATEVER"), and I'm trying to get the 0.9 release wrapped up soon

@sgrif sgrif removed this from the 0.9 milestone Dec 6, 2016

sgrif added a commit that referenced this issue Jan 7, 2018

Support specifying details about a PG transaction
This adds support for all options which can be given to `SET
TRANSACTION`. We only expose an API for this when opening the
transaction though, as `SET TRANSACTION` errors unless it's the first
query run after opening the transaction.

Most of the tests are really just there to make sure the code compiles
and generates valid SQL. Seeing *a* usage example is still worth having,
but I don't think we can effectively demonstrate/test the differences
between isolation levels in a reasonable manner.

This lays some groundwork that will also be used by #1356, but I haven't
implemented SQLite support yet. The APIs for this will be backend
specific, not trait based.

Fixes #408.

sgrif added a commit that referenced this issue Jan 7, 2018

Support specifying details about a PG transaction
This adds support for all options which can be given to `SET
TRANSACTION`. We only expose an API for this when opening the
transaction though, as `SET TRANSACTION` errors unless it's the first
query run after opening the transaction.

Most of the tests are really just there to make sure the code compiles
and generates valid SQL. Seeing *a* usage example is still worth having,
but I don't think we can effectively demonstrate/test the differences
between isolation levels in a reasonable manner.

This lays some groundwork that will also be used by #1356, but I haven't
implemented SQLite support yet. The APIs for this will be backend
specific, not trait based.

Fixes #408.

sgrif added a commit that referenced this issue Jan 7, 2018

Support specifying details about a PG transaction
This adds support for all options which can be given to `SET
TRANSACTION`. We only expose an API for this when opening the
transaction though, as `SET TRANSACTION` errors unless it's the first
query run after opening the transaction.

Most of the tests are really just there to make sure the code compiles
and generates valid SQL. Seeing *a* usage example is still worth having,
but I don't think we can effectively demonstrate/test the differences
between isolation levels in a reasonable manner.

This lays some groundwork that will also be used by #1356, but I haven't
implemented SQLite support yet. The APIs for this will be backend
specific, not trait based.

Fixes #408.

sgrif added a commit that referenced this issue Jan 17, 2018

Support specifying details about a PG transaction
This adds support for all options which can be given to `SET
TRANSACTION`. We only expose an API for this when opening the
transaction though, as `SET TRANSACTION` errors unless it's the first
query run after opening the transaction.

Most of the tests are really just there to make sure the code compiles
and generates valid SQL. Seeing *a* usage example is still worth having,
but I don't think we can effectively demonstrate/test the differences
between isolation levels in a reasonable manner.

This lays some groundwork that will also be used by #1356, but I haven't
implemented SQLite support yet. The APIs for this will be backend
specific, not trait based.

Fixes #408.

@sgrif sgrif closed this in #1462 Jan 18, 2018

sgrif added a commit that referenced this issue Jan 18, 2018

Support specifying details about a PG transaction (#1462)
This adds support for all options which can be given to `SET
TRANSACTION`. We only expose an API for this when opening the
transaction though, as `SET TRANSACTION` errors unless it's the first
query run after opening the transaction.

Most of the tests are really just there to make sure the code compiles
and generates valid SQL. Seeing *a* usage example is still worth having,
but I don't think we can effectively demonstrate/test the differences
between isolation levels in a reasonable manner.

This lays some groundwork that will also be used by #1356, but I haven't
implemented SQLite support yet. The APIs for this will be backend
specific, not trait based.

Fixes #408.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment