@@ -378,23 +378,55 @@ impl Connection {
378378 values : impl ValueList ,
379379 ) -> Result < QueryResult , QueryError > {
380380 let query: Query = query. into ( ) ;
381- self . query ( & query, & values, None ) . await ?. into_query_result ( )
381+ let consistency = query
382+ . config
383+ . determine_consistency ( self . config . default_consistency ) ;
384+ self . query_single_page_with_consistency ( query, & values, consistency)
385+ . await
386+ }
387+
388+ pub async fn query_single_page_with_consistency (
389+ & self ,
390+ query : impl Into < Query > ,
391+ values : impl ValueList ,
392+ consistency : Consistency ,
393+ ) -> Result < QueryResult , QueryError > {
394+ let query: Query = query. into ( ) ;
395+ self . query_with_consistency ( & query, & values, consistency, None )
396+ . await ?
397+ . into_query_result ( )
382398 }
383399
384400 pub async fn query (
385401 & self ,
386402 query : & Query ,
387403 values : impl ValueList ,
388404 paging_state : Option < Bytes > ,
405+ ) -> Result < QueryResponse , QueryError > {
406+ self . query_with_consistency (
407+ query,
408+ values,
409+ query
410+ . config
411+ . determine_consistency ( self . config . default_consistency ) ,
412+ paging_state,
413+ )
414+ . await
415+ }
416+
417+ pub async fn query_with_consistency (
418+ & self ,
419+ query : & Query ,
420+ values : impl ValueList ,
421+ consistency : Consistency ,
422+ paging_state : Option < Bytes > ,
389423 ) -> Result < QueryResponse , QueryError > {
390424 let serialized_values = values. serialized ( ) ?;
391425
392426 let query_frame = query:: Query {
393427 contents : & query. contents ,
394428 parameters : query:: QueryParameters {
395- consistency : query
396- . config
397- . determine_consistency ( self . config . default_consistency ) ,
429+ consistency,
398430 serial_consistency : query. get_serial_consistency ( ) ,
399431 values : & serialized_values,
400432 page_size : query. get_page_size ( ) ,
@@ -412,6 +444,22 @@ impl Connection {
412444 & self ,
413445 query : & Query ,
414446 values : impl ValueList ,
447+ ) -> Result < QueryResult , QueryError > {
448+ self . query_all_with_consistency (
449+ query,
450+ values,
451+ query
452+ . config
453+ . determine_consistency ( self . config . default_consistency ) ,
454+ )
455+ . await
456+ }
457+
458+ pub async fn query_all_with_consistency (
459+ & self ,
460+ query : & Query ,
461+ values : impl ValueList ,
462+ consistency : Consistency ,
415463 ) -> Result < QueryResult , QueryError > {
416464 if query. get_page_size ( ) . is_none ( ) {
417465 // Page size should be set when someone wants to use paging
@@ -426,10 +474,14 @@ impl Connection {
426474 let serialized_values = values. serialized ( ) ?;
427475 let mut paging_state: Option < Bytes > = None ;
428476
477+ query
478+ . config
479+ . determine_consistency ( self . config . default_consistency ) ;
480+
429481 loop {
430482 // Send next paged query
431483 let mut cur_result: QueryResult = self
432- . query ( query, & serialized_values, paging_state)
484+ . query_with_consistency ( query, & serialized_values, consistency , paging_state)
433485 . await ?
434486 . into_query_result ( ) ?;
435487
@@ -462,15 +514,31 @@ impl Connection {
462514 prepared_statement : & PreparedStatement ,
463515 values : impl ValueList ,
464516 paging_state : Option < Bytes > ,
517+ ) -> Result < QueryResponse , QueryError > {
518+ self . execute_with_consistency (
519+ prepared_statement,
520+ values,
521+ prepared_statement
522+ . config
523+ . determine_consistency ( self . config . default_consistency ) ,
524+ paging_state,
525+ )
526+ . await
527+ }
528+
529+ pub async fn execute_with_consistency (
530+ & self ,
531+ prepared_statement : & PreparedStatement ,
532+ values : impl ValueList ,
533+ consistency : Consistency ,
534+ paging_state : Option < Bytes > ,
465535 ) -> Result < QueryResponse , QueryError > {
466536 let serialized_values = values. serialized ( ) ?;
467537
468538 let execute_frame = execute:: Execute {
469539 id : prepared_statement. get_id ( ) . to_owned ( ) ,
470540 parameters : query:: QueryParameters {
471- consistency : prepared_statement
472- . config
473- . determine_consistency ( self . config . default_consistency ) ,
541+ consistency,
474542 serial_consistency : prepared_statement. get_serial_consistency ( ) ,
475543 values : & serialized_values,
476544 page_size : prepared_statement. get_page_size ( ) ,
@@ -544,10 +612,27 @@ impl Connection {
544612 }
545613 }
546614
615+ #[ allow( dead_code) ]
547616 pub async fn batch (
548617 & self ,
549618 batch : & Batch ,
550619 values : impl BatchValues ,
620+ ) -> Result < BatchResult , QueryError > {
621+ self . batch_with_consistency (
622+ batch,
623+ values,
624+ batch
625+ . config
626+ . determine_consistency ( self . config . default_consistency ) ,
627+ )
628+ . await
629+ }
630+
631+ pub async fn batch_with_consistency (
632+ & self ,
633+ batch : & Batch ,
634+ values : impl BatchValues ,
635+ consistency : Consistency ,
551636 ) -> Result < BatchResult , QueryError > {
552637 let statements_count = batch. statements . len ( ) ;
553638 if statements_count != values. len ( ) {
@@ -569,9 +654,7 @@ impl Connection {
569654 statements_count,
570655 values,
571656 batch_type : batch. get_type ( ) ,
572- consistency : batch
573- . config
574- . determine_consistency ( self . config . default_consistency ) ,
657+ consistency,
575658 serial_consistency : batch. get_serial_consistency ( ) ,
576659 timestamp : batch. get_timestamp ( ) ,
577660 } ;
0 commit comments