-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implement transaction options API #1827
Changes from all commits
b3fc0c9
82efe5c
87ca247
afba195
ca7a9ad
2b09ca9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use crate::database::{Database, HasStatementCache}; | ||
use crate::error::Error; | ||
use crate::transaction::Transaction; | ||
use crate::transaction::{Transaction, TransactionManager}; | ||
use futures_core::future::BoxFuture; | ||
use log::LevelFilter; | ||
use std::fmt::Debug; | ||
|
@@ -27,6 +27,19 @@ pub trait Connection: Send { | |
/// | ||
/// Returns a [`Transaction`] for controlling and tracking the new transaction. | ||
fn begin(&mut self) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>> | ||
where | ||
Self: Sized, | ||
{ | ||
Self::begin_with(self, Default::default()) | ||
} | ||
|
||
/// Begin a new transaction or establish a savepoint within the active transaction. | ||
/// | ||
/// Returns a [`Transaction`] for controlling and tracking the new transaction. | ||
fn begin_with( | ||
&mut self, | ||
options: <<Self::Database as Database>::TransactionManager as TransactionManager>::Options, | ||
) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, I should have looked at this PR before releasing 0.6.0 because this is a breaking change. While it's unlikely that any implementation of this trait exists outside SQLx, since we haven't sealed any of them it's not impossible. |
||
where | ||
Self: Sized; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,9 @@ pub struct MssqlTransactionManager; | |
|
||
impl TransactionManager for MssqlTransactionManager { | ||
type Database = Mssql; | ||
type Options = (); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would prefer to see at least an empty |
||
|
||
fn begin(conn: &mut MssqlConnection) -> BoxFuture<'_, Result<(), Error>> { | ||
fn begin_with(conn: &mut MssqlConnection, _options: ()) -> BoxFuture<'_, Result<(), Error>> { | ||
Box::pin(async move { | ||
let depth = conn.stream.transaction_depth; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think this could be a struct containing a
TransactionOptions
for each database, and then the implementation picks the corresponding one:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could then have setters to replace each type wholesale:
Or even have setters for "best effort" options:
(Since
PgIsolationLevel
andMySqlIsolationLevel
are identical, they don't need to be separate enums.)