Skip to content

Commit 22f28cd

Browse files
piodulwprzytula
andcommitted
session: add interface methods for the new deser API
Implements methods related to sending queries for the new Session. Co-authored-by: Wojciech Przytuła <[email protected]>
1 parent c229ae5 commit 22f28cd

File tree

1 file changed

+91
-29
lines changed

1 file changed

+91
-29
lines changed

scylla/src/transport/session.rs

Lines changed: 91 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ pub(crate) enum RunQueryResult<ResT> {
462462
Completed(ResT),
463463
}
464464

465-
impl GenericSession<LegacyDeserializationApi> {
465+
impl GenericSession<CurrentDeserializationApi> {
466466
/// Sends a request to the database and receives a response.\
467467
/// Performs an unpaged query, i.e. all results are received in a single response.
468468
///
@@ -526,11 +526,8 @@ impl GenericSession<LegacyDeserializationApi> {
526526
&self,
527527
query: impl Into<Query>,
528528
values: impl SerializeRow,
529-
) -> Result<LegacyQueryResult, QueryError> {
530-
Ok(self
531-
.do_query_unpaged(&query.into(), values)
532-
.await?
533-
.into_legacy_result()?)
529+
) -> Result<QueryResult, QueryError> {
530+
self.do_query_unpaged(&query.into(), values).await
534531
}
535532

536533
/// Queries a single page from the database, optionally continuing from a saved point.
@@ -586,11 +583,9 @@ impl GenericSession<LegacyDeserializationApi> {
586583
query: impl Into<Query>,
587584
values: impl SerializeRow,
588585
paging_state: PagingState,
589-
) -> Result<(LegacyQueryResult, PagingStateResponse), QueryError> {
590-
let (result, paging_state_response) = self
591-
.do_query_single_page(&query.into(), values, paging_state)
592-
.await?;
593-
Ok((result.into_legacy_result()?, paging_state_response))
586+
) -> Result<(QueryResult, PagingStateResponse), QueryError> {
587+
self.do_query_single_page(&query.into(), values, paging_state)
588+
.await
594589
}
595590

596591
/// Run an unprepared query with paging\
@@ -634,10 +629,8 @@ impl GenericSession<LegacyDeserializationApi> {
634629
&self,
635630
query: impl Into<Query>,
636631
values: impl SerializeRow,
637-
) -> Result<LegacyRowIterator, QueryError> {
638-
self.do_query_iter(query.into(), values)
639-
.await
640-
.map(QueryPager::into_legacy)
632+
) -> Result<QueryPager, QueryError> {
633+
self.do_query_iter(query.into(), values).await
641634
}
642635

643636
/// Execute a prepared statement. Requires a [PreparedStatement]
@@ -687,11 +680,8 @@ impl GenericSession<LegacyDeserializationApi> {
687680
&self,
688681
prepared: &PreparedStatement,
689682
values: impl SerializeRow,
690-
) -> Result<LegacyQueryResult, QueryError> {
691-
Ok(self
692-
.do_execute_unpaged(prepared, values)
693-
.await?
694-
.into_legacy_result()?)
683+
) -> Result<QueryResult, QueryError> {
684+
self.do_execute_unpaged(prepared, values).await
695685
}
696686

697687
/// Executes a prepared statement, restricting results to single page.
@@ -752,11 +742,9 @@ impl GenericSession<LegacyDeserializationApi> {
752742
prepared: &PreparedStatement,
753743
values: impl SerializeRow,
754744
paging_state: PagingState,
755-
) -> Result<(LegacyQueryResult, PagingStateResponse), QueryError> {
756-
let (result, paging_state_response) = self
757-
.do_execute_single_page(prepared, values, paging_state)
758-
.await?;
759-
Ok((result.into_legacy_result()?, paging_state_response))
745+
) -> Result<(QueryResult, PagingStateResponse), QueryError> {
746+
self.do_execute_single_page(prepared, values, paging_state)
747+
.await
760748
}
761749

762750
/// Run a prepared query with paging.\
@@ -803,10 +791,8 @@ impl GenericSession<LegacyDeserializationApi> {
803791
&self,
804792
prepared: impl Into<PreparedStatement>,
805793
values: impl SerializeRow,
806-
) -> Result<LegacyRowIterator, QueryError> {
807-
self.do_execute_iter(prepared.into(), values)
808-
.await
809-
.map(QueryPager::into_legacy)
794+
) -> Result<QueryPager, QueryError> {
795+
self.do_execute_iter(prepared.into(), values).await
810796
}
811797

812798
/// Perform a batch query\
@@ -854,6 +840,82 @@ impl GenericSession<LegacyDeserializationApi> {
854840
/// # Ok(())
855841
/// # }
856842
/// ```
843+
pub async fn batch(
844+
&self,
845+
batch: &Batch,
846+
values: impl BatchValues,
847+
) -> Result<QueryResult, QueryError> {
848+
self.do_batch(batch, values).await
849+
}
850+
}
851+
852+
impl GenericSession<LegacyDeserializationApi> {
853+
pub async fn query_unpaged(
854+
&self,
855+
query: impl Into<Query>,
856+
values: impl SerializeRow,
857+
) -> Result<LegacyQueryResult, QueryError> {
858+
Ok(self
859+
.do_query_unpaged(&query.into(), values)
860+
.await?
861+
.into_legacy_result()?)
862+
}
863+
864+
pub async fn query_single_page(
865+
&self,
866+
query: impl Into<Query>,
867+
values: impl SerializeRow,
868+
paging_state: PagingState,
869+
) -> Result<(LegacyQueryResult, PagingStateResponse), QueryError> {
870+
let (result, paging_state_response) = self
871+
.do_query_single_page(&query.into(), values, paging_state)
872+
.await?;
873+
Ok((result.into_legacy_result()?, paging_state_response))
874+
}
875+
876+
pub async fn query_iter(
877+
&self,
878+
query: impl Into<Query>,
879+
values: impl SerializeRow,
880+
) -> Result<LegacyRowIterator, QueryError> {
881+
self.do_query_iter(query.into(), values)
882+
.await
883+
.map(QueryPager::into_legacy)
884+
}
885+
886+
pub async fn execute_unpaged(
887+
&self,
888+
prepared: &PreparedStatement,
889+
values: impl SerializeRow,
890+
) -> Result<LegacyQueryResult, QueryError> {
891+
Ok(self
892+
.do_execute_unpaged(prepared, values)
893+
.await?
894+
.into_legacy_result()?)
895+
}
896+
897+
pub async fn execute_single_page(
898+
&self,
899+
prepared: &PreparedStatement,
900+
values: impl SerializeRow,
901+
paging_state: PagingState,
902+
) -> Result<(LegacyQueryResult, PagingStateResponse), QueryError> {
903+
let (result, paging_state_response) = self
904+
.do_execute_single_page(prepared, values, paging_state)
905+
.await?;
906+
Ok((result.into_legacy_result()?, paging_state_response))
907+
}
908+
909+
pub async fn execute_iter(
910+
&self,
911+
prepared: impl Into<PreparedStatement>,
912+
values: impl SerializeRow,
913+
) -> Result<LegacyRowIterator, QueryError> {
914+
self.do_execute_iter(prepared.into(), values)
915+
.await
916+
.map(QueryPager::into_legacy)
917+
}
918+
857919
pub async fn batch(
858920
&self,
859921
batch: &Batch,

0 commit comments

Comments
 (0)