Skip to content

Commit e5ad490

Browse files
RUST-90 Implement Transactions API (#332)
1 parent dfb484b commit e5ad490

File tree

42 files changed

+1982
-433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1982
-433
lines changed

src/client/executor.rs

Lines changed: 210 additions & 53 deletions
Large diffs are not rendered by default.

src/client/options/mod.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ use serde::{
3030
de::{Error, Unexpected},
3131
Deserialize,
3232
Deserializer,
33+
Serialize,
3334
};
35+
use serde_with::skip_serializing_none;
3436
use strsim::jaro_winkler;
3537
use typed_builder::TypedBuilder;
3638
use webpki_roots::TLS_SERVER_ROOTS;
3739

3840
use crate::{
3941
bson::{doc, Bson, Document},
42+
bson_util::{deserialize_duration_from_u64_millis, serialize_duration_as_int_millis},
4043
client::auth::{AuthMechanism, Credential},
4144
concern::{Acknowledgment, ReadConcern, WriteConcern},
4245
error::{ErrorKind, Result},
@@ -2146,4 +2149,47 @@ mod tests {
21462149
/// [`ClientSession`](../struct.ClientSession.html).
21472150
#[derive(Clone, Debug, Deserialize, TypedBuilder)]
21482151
#[builder(field_defaults(default, setter(strip_option)))]
2149-
pub struct SessionOptions {}
2152+
#[serde(rename_all = "camelCase")]
2153+
#[non_exhaustive]
2154+
pub struct SessionOptions {
2155+
/// The default options to use for transactions started on this session.
2156+
///
2157+
/// If these options are not specified, they will be inherited from the
2158+
/// [`Client`](../struct.Client.html) associated with this session. They will not
2159+
/// be inherited from the options specified
2160+
/// on the [`Database`](../struct.Database.html) or [`Collection`](../struct.Collection.html)
2161+
/// associated with the operations within the transaction.
2162+
pub default_transaction_options: Option<TransactionOptions>,
2163+
}
2164+
2165+
/// Contains the options that can be used for a transaction.
2166+
#[skip_serializing_none]
2167+
#[derive(Debug, Default, Serialize, Deserialize, TypedBuilder, Clone)]
2168+
#[builder(field_defaults(default, setter(strip_option)))]
2169+
#[serde(rename_all = "camelCase")]
2170+
#[non_exhaustive]
2171+
pub struct TransactionOptions {
2172+
/// The read concern to use for the transaction.
2173+
#[builder(default)]
2174+
#[serde(skip_serializing)]
2175+
pub read_concern: Option<ReadConcern>,
2176+
2177+
/// The write concern to use when committing or aborting a transaction.
2178+
#[builder(default)]
2179+
pub write_concern: Option<WriteConcern>,
2180+
2181+
/// The selection criteria to use for all read operations in a transaction.
2182+
#[builder(default)]
2183+
#[serde(skip_serializing, rename = "readPreference")]
2184+
pub selection_criteria: Option<SelectionCriteria>,
2185+
2186+
/// The maximum amount of time to allow a single commitTransaction to run.
2187+
#[builder(default)]
2188+
#[serde(
2189+
serialize_with = "serialize_duration_as_int_millis",
2190+
deserialize_with = "deserialize_duration_from_u64_millis",
2191+
rename(serialize = "maxTimeMS", deserialize = "maxCommitTimeMS"),
2192+
default
2193+
)]
2194+
pub max_commit_time: Option<Duration>,
2195+
}

0 commit comments

Comments
 (0)