use crate::models::ThroughputProperties;
use crate::ContinuationToken;
use std::fmt;
use std::fmt::Display;
#[doc(inline)]
pub use azure_data_cosmos_driver::models::{
ETag, MaxItemCountHint, Precondition, SessionToken, ThroughputControlGroupName,
};
#[doc(inline)]
pub use azure_data_cosmos_driver::options::{
ContentResponseOnWrite, EndToEndOperationLatencyPolicy, ExcludedRegions, OperationOptions,
OperationOptionsBuilder, OperationOptionsView, PriorityLevel, ReadConsistencyStrategy, Region,
ThroughputControlGroupOptions, UserAgentSuffix,
};
#[derive(Clone, Default, Debug)]
#[non_exhaustive]
pub struct CosmosClientOptions {
pub(crate) operation: OperationOptions,
pub(crate) user_agent_suffix: Option<UserAgentSuffix>,
}
impl CosmosClientOptions {
pub fn with_user_agent_suffix(mut self, suffix: UserAgentSuffix) -> Self {
self.user_agent_suffix = Some(suffix);
self
}
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct CreateContainerOptions {
pub operation: OperationOptions,
pub(crate) throughput: Option<ThroughputProperties>,
}
impl CreateContainerOptions {
pub fn with_throughput(mut self, throughput: ThroughputProperties) -> Self {
self.throughput = Some(throughput);
self
}
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct ReplaceContainerOptions {
pub operation: OperationOptions,
}
impl ReplaceContainerOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct CreateDatabaseOptions {
pub operation: OperationOptions,
}
impl CreateDatabaseOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct DeleteContainerOptions {
pub operation: OperationOptions,
}
impl DeleteContainerOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct DeleteDatabaseOptions {
pub operation: OperationOptions,
}
impl DeleteDatabaseOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Debug)]
pub enum ConsistencyLevel {
ConsistentPrefix,
Eventual,
Session,
BoundedStaleness,
Strong,
}
impl Display for ConsistencyLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let value = match self {
ConsistencyLevel::ConsistentPrefix => "ConsistentPrefix",
ConsistencyLevel::Eventual => "Eventual",
ConsistencyLevel::Session => "Session",
ConsistencyLevel::BoundedStaleness => "BoundedStaleness",
ConsistencyLevel::Strong => "Strong",
};
write!(f, "{}", value)
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct ItemReadOptions {
pub operation: OperationOptions,
pub session_token: Option<SessionToken>,
pub precondition: Option<Precondition>,
}
impl ItemReadOptions {
pub fn with_session_token(mut self, session_token: impl Into<SessionToken>) -> Self {
self.session_token = Some(session_token.into());
self
}
pub fn with_precondition(mut self, precondition: Precondition) -> Self {
self.precondition = Some(precondition);
self
}
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct ItemWriteOptions {
pub operation: OperationOptions,
pub session_token: Option<SessionToken>,
pub precondition: Option<Precondition>,
}
impl ItemWriteOptions {
pub fn with_session_token(mut self, session_token: impl Into<SessionToken>) -> Self {
self.session_token = Some(session_token.into());
self
}
pub fn with_precondition(mut self, precondition: Precondition) -> Self {
self.precondition = Some(precondition);
self
}
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct PatchItemOptions {
pub operation: OperationOptions,
pub session_token: Option<SessionToken>,
pub max_attempts: Option<std::num::NonZeroU8>,
}
impl PatchItemOptions {
pub fn with_session_token(mut self, session_token: impl Into<SessionToken>) -> Self {
self.session_token = Some(session_token.into());
self
}
pub fn with_max_attempts(mut self, max_attempts: std::num::NonZeroU8) -> Self {
self.max_attempts = Some(max_attempts);
self
}
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct BatchOptions {
pub operation: OperationOptions,
pub session_token: Option<SessionToken>,
}
impl BatchOptions {
pub fn with_session_token(mut self, session_token: impl Into<SessionToken>) -> Self {
self.session_token = Some(session_token.into());
self
}
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct QueryContainersOptions {
pub operation: OperationOptions,
}
impl QueryContainersOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct QueryDatabasesOptions {
pub operation: OperationOptions,
}
impl QueryDatabasesOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct FeedOptions {
pub max_item_count: Option<MaxItemCountHint>,
pub continuation_token: Option<ContinuationToken>,
}
impl FeedOptions {
pub fn with_max_item_count(mut self, max_item_count: MaxItemCountHint) -> Self {
self.max_item_count = Some(max_item_count);
self
}
pub fn with_continuation_token(mut self, continuation_token: ContinuationToken) -> Self {
self.continuation_token = Some(continuation_token);
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct QueryOptions {
pub operation: OperationOptions,
pub feed: FeedOptions,
pub session_token: Option<SessionToken>,
pub populate_index_metrics: Option<bool>,
pub populate_query_metrics: Option<bool>,
}
impl QueryOptions {
pub fn with_session_token(mut self, session_token: impl Into<SessionToken>) -> Self {
self.session_token = Some(session_token.into());
self
}
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
pub fn with_feed_options(mut self, feed: FeedOptions) -> Self {
self.feed = feed;
self
}
pub fn with_populate_index_metrics(mut self, enable: bool) -> Self {
self.populate_index_metrics = Some(enable);
self
}
pub fn with_populate_query_metrics(mut self, enable: bool) -> Self {
self.populate_query_metrics = Some(enable);
self
}
pub fn with_max_item_count(mut self, max_item_count: MaxItemCountHint) -> Self {
self.feed = self.feed.with_max_item_count(max_item_count);
self
}
pub fn with_continuation_token(mut self, continuation_token: ContinuationToken) -> Self {
self.feed = self.feed.with_continuation_token(continuation_token);
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct ReadContainerOptions {
pub operation: OperationOptions,
}
impl ReadContainerOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct ReadDatabaseOptions {
pub operation: OperationOptions,
}
impl ReadDatabaseOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct ThroughputOptions {
pub operation: OperationOptions,
}
impl ThroughputOptions {
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
}
#[derive(Clone, Default, Debug)]
#[non_exhaustive]
pub struct ReadFeedRangesOptions {
pub operation: OperationOptions,
force_refresh: bool,
}
impl ReadFeedRangesOptions {
pub fn with_force_refresh(mut self, force_refresh: bool) -> Self {
self.force_refresh = force_refresh;
self
}
pub fn with_operation_options(mut self, operation: OperationOptions) -> Self {
self.operation = operation;
self
}
pub(crate) fn force_refresh(&self) -> bool {
self.force_refresh
}
}