aws_sdk_dynamodb/operation/query/
paginator.rs1pub struct QueryPaginator {
4 handle: std::sync::Arc<crate::client::Handle>,
5 builder: crate::operation::query::builders::QueryInputBuilder,
6 stop_on_duplicate_token: bool,
7}
8
9impl QueryPaginator {
10 pub(crate) fn new(handle: std::sync::Arc<crate::client::Handle>, builder: crate::operation::query::builders::QueryInputBuilder) -> Self {
12 Self {
13 handle,
14 builder,
15 stop_on_duplicate_token: true,
16 }
17 }
18
19 pub fn page_size(mut self, limit: i32) -> Self {
23 self.builder.limit = ::std::option::Option::Some(limit);
24 self
25 }
26
27 pub fn items(self) -> crate::operation::query::paginator::QueryPaginatorItems {
32 crate::operation::query::paginator::QueryPaginatorItems(self)
33 }
34
35 pub fn stop_on_duplicate_token(mut self, stop_on_duplicate_token: bool) -> Self {
43 self.stop_on_duplicate_token = stop_on_duplicate_token;
44 self
45 }
46
47 pub fn send(
52 self,
53 ) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<
54 ::std::result::Result<
55 crate::operation::query::QueryOutput,
56 ::aws_smithy_runtime_api::client::result::SdkError<
57 crate::operation::query::QueryError,
58 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
59 >,
60 >,
61 > {
62 let builder = self.builder;
64 let handle = self.handle;
65 let runtime_plugins =
66 crate::operation::query::Query::operation_runtime_plugins(handle.runtime_plugins.clone(), &handle.conf, ::std::option::Option::None)
67 .with_operation_plugin(crate::sdk_feature_tracker::paginator::PaginatorFeatureTrackerRuntimePlugin::new());
68 ::aws_smithy_async::future::pagination_stream::PaginationStream::new(::aws_smithy_async::future::pagination_stream::fn_stream::FnStream::new(
69 move |tx| {
70 ::std::boxed::Box::pin(async move {
71 let mut input = match builder
73 .build()
74 .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)
75 {
76 ::std::result::Result::Ok(input) => input,
77 ::std::result::Result::Err(e) => {
78 let _ = tx.send(::std::result::Result::Err(e)).await;
79 return;
80 }
81 };
82 loop {
83 let resp = crate::operation::query::Query::orchestrate(&runtime_plugins, input.clone()).await;
84 let done = match resp {
86 ::std::result::Result::Ok(ref resp) => {
87 let new_token = crate::lens::reflens_query_output_output_last_evaluated_key(resp);
88 let is_empty = new_token.map(|token| token.is_empty()).unwrap_or(true);
90 if !is_empty && new_token == input.exclusive_start_key.as_ref() && self.stop_on_duplicate_token {
91 true
92 } else {
93 input.exclusive_start_key = new_token.cloned();
94 is_empty
95 }
96 }
97 ::std::result::Result::Err(_) => true,
98 };
99 if tx.send(resp).await.is_err() {
100 return;
102 }
103 if done {
104 return;
105 }
106 }
107 })
108 },
109 ))
110 }
111}
112
113pub struct QueryPaginatorItems(QueryPaginator);
117
118impl QueryPaginatorItems {
119 pub fn send(
126 self,
127 ) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<
128 ::std::result::Result<
129 ::std::collections::HashMap<::std::string::String, crate::types::AttributeValue>,
130 ::aws_smithy_runtime_api::client::result::SdkError<
131 crate::operation::query::QueryError,
132 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
133 >,
134 >,
135 > {
136 ::aws_smithy_async::future::pagination_stream::TryFlatMap::new(self.0.send())
137 .flat_map(|page| crate::lens::lens_query_output_output_items(page).unwrap_or_default().into_iter())
138 }
139}