@@ -20,6 +20,7 @@ use super::{Dynamo, EncryptedTable, QueryError, ScopedZeroKmsCipher, SealError};
2020pub struct QueryBuilder < S , B = ( ) > {
2121 parts : Vec < ( String , SingleIndex , Plaintext ) > ,
2222 storage : B ,
23+ dataset_id : Option < Uuid > ,
2324 __searchable : PhantomData < S > ,
2425}
2526
@@ -93,6 +94,7 @@ impl<S> Default for QueryBuilder<S> {
9394 Self {
9495 parts : vec ! [ ] ,
9596 storage : Default :: default ( ) ,
97+ dataset_id : None ,
9698 __searchable : Default :: default ( ) ,
9799 }
98100 }
@@ -103,10 +105,17 @@ impl<S, B> QueryBuilder<S, B> {
103105 Self {
104106 parts : vec ! [ ] ,
105107 storage : backend,
108+ dataset_id : None ,
106109 __searchable : Default :: default ( ) ,
107110 }
108111 }
109112
113+ /// Specify the dataset to query against.
114+ pub fn via ( mut self , dataset_id : Uuid ) -> Self {
115+ self . dataset_id = Some ( dataset_id) ;
116+ self
117+ }
118+
110119 pub fn eq ( mut self , name : impl Into < String > , plaintext : impl Into < Plaintext > ) -> Self {
111120 self . parts
112121 . push ( ( name. into ( ) , SingleIndex :: Exact , plaintext. into ( ) ) ) ;
@@ -138,27 +147,12 @@ where
138147 ///
139148 /// While a client can decrypt records from any dataset it has access to,
140149 /// queries are always scoped to a single dataset.
141- pub async fn load < T > ( self ) -> Result < Vec < T > , QueryError >
142- where
143- T : Decryptable + Identifiable ,
144- {
145- self . load_inner ( None ) . await
146- }
147-
148- /// Similar to `load`, but the query is scoped to a specific dataset.
149- pub async fn load_via < T > ( self , dataset_id : Uuid ) -> Result < Vec < T > , QueryError >
150- where
151- T : Decryptable + Identifiable ,
152- {
153- self . load_inner ( Some ( dataset_id) ) . await
154- }
155-
156- async fn load_inner < T > ( self , dataset_id : Option < Uuid > ) -> Result < Vec < T > , QueryError >
150+ pub ( crate ) async fn load < T > ( self ) -> Result < Vec < T > , QueryError >
157151 where
158152 T : Decryptable + Identifiable ,
159153 {
160154 let scoped_cipher =
161- ScopedZeroKmsCipher :: init ( self . storage . cipher . clone ( ) , dataset_id) . await ?;
155+ ScopedZeroKmsCipher :: init ( self . storage . cipher . clone ( ) , self . dataset_id ) . await ?;
162156
163157 let storage = self . storage ;
164158 let query = self . build ( ) ?;
0 commit comments