mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
wip: plan out transaction options, to mirror connect options
This commit is contained in:
parent
1227b934c8
commit
301665360c
24
sqlx-core/src/isolation_level.rs
Normal file
24
sqlx-core/src/isolation_level.rs
Normal file
@ -0,0 +1,24 @@
|
||||
/// Transaction isolation level; controls the degree of locking that occurs
|
||||
/// when selecting data.
|
||||
///
|
||||
/// See <https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels>.
|
||||
///
|
||||
pub enum IsolationLevel {
|
||||
/// The lowest isolation level. Dirty reads are allowed, so one transaction
|
||||
/// may see **not yet committed** changes made by other transactions.
|
||||
ReadUncommitted,
|
||||
|
||||
/// A `SELECT` query will only see data that has been committed before the
|
||||
/// query began.
|
||||
///
|
||||
/// However, two successive `SELECT` queries can see different data,
|
||||
/// even though they are within a single transaction, if a concurrent
|
||||
/// transaction has committed in-between.
|
||||
ReadCommitted,
|
||||
|
||||
/// A `SELECT` query will only see data committed before the transaction
|
||||
/// began.
|
||||
RepeatableRead,
|
||||
|
||||
Serializable,
|
||||
}
|
||||
@ -31,6 +31,7 @@ pub mod encode;
|
||||
mod error;
|
||||
mod execute;
|
||||
mod executor;
|
||||
mod isolation_level;
|
||||
mod options;
|
||||
mod query_result;
|
||||
pub mod row;
|
||||
@ -65,6 +66,7 @@ pub use encode::Encode;
|
||||
pub use error::{DatabaseError, Error, Result};
|
||||
pub use execute::Execute;
|
||||
pub use executor::Executor;
|
||||
pub use isolation_level::IsolationLevel;
|
||||
pub use options::ConnectOptions;
|
||||
pub use query_result::QueryResult;
|
||||
pub use r#type::{Type, TypeDecode, TypeEncode};
|
||||
|
||||
@ -5,7 +5,7 @@ use sqlx_core::DatabaseError;
|
||||
|
||||
use crate::protocol::ErrPacket;
|
||||
|
||||
/// An error returned from the MySQL database server.
|
||||
/// An error returned from the MySQL database.
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Debug)]
|
||||
pub struct MySqlDatabaseError(pub(crate) ErrPacket);
|
||||
|
||||
@ -20,6 +20,8 @@
|
||||
#![allow(clippy::missing_errors_doc)]
|
||||
#![allow(clippy::missing_panics_doc)]
|
||||
|
||||
use sqlx_core::Arguments;
|
||||
|
||||
#[macro_use]
|
||||
mod stream;
|
||||
|
||||
@ -35,6 +37,7 @@ mod query_result;
|
||||
mod raw_statement;
|
||||
mod raw_value;
|
||||
mod row;
|
||||
mod transaction;
|
||||
mod type_id;
|
||||
mod type_info;
|
||||
pub mod types;
|
||||
@ -53,3 +56,5 @@ pub use raw_value::{MySqlRawValue, MySqlRawValueFormat};
|
||||
pub use row::MySqlRow;
|
||||
pub use type_id::MySqlTypeId;
|
||||
pub use type_info::MySqlTypeInfo;
|
||||
|
||||
pub type MySqlArguments<'a> = Arguments<'a, MySql>;
|
||||
|
||||
31
sqlx-mysql/src/transaction.rs
Normal file
31
sqlx-mysql/src/transaction.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use sqlx_core::IsolationLevel;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MySqlTransactionOptions {
|
||||
with_consistent_snapshot: bool,
|
||||
read_only: bool,
|
||||
isolation_level: IsolationLevel,
|
||||
}
|
||||
|
||||
impl MySqlTransactionOptions {
|
||||
pub fn read_only(&mut self) -> &mut Self {
|
||||
self.read_only = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_consistent_snapshot(&mut self) -> &mut Self {
|
||||
self.with_consistent_snapshot = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn isolation(&mut self, level: IsolationLevel) -> &mut Self {
|
||||
self.isolation_level = level;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
// impl MySqlTransactionOptions {
|
||||
// pub fn begin(&self) -> MySqlTransaction {
|
||||
// // [..]
|
||||
// }
|
||||
// }
|
||||
Loading…
x
Reference in New Issue
Block a user