@@ -7,31 +7,27 @@ use std::future::Future;
77mod common;
88
99#[ derive( Encryptable , Decryptable , Searchable , Debug , PartialEq , Ord , PartialOrd , Eq ) ]
10- #[ cryptonamo( sort_key_prefix = "user" ) ]
1110pub struct User {
12- #[ cryptonamo( query = "exact" , compound = "pk#name " ) ]
11+ #[ cryptonamo( query = "exact" , compound = "pk#sk " ) ]
1312 #[ cryptonamo( query = "exact" ) ]
1413 #[ partition_key]
1514 pub pk : String ,
1615
17- #[ cryptonamo( query = "prefix" , compound = "pk#name " ) ]
16+ #[ cryptonamo( query = "prefix" , compound = "pk#sk " ) ]
1817 #[ cryptonamo( query = "prefix" ) ]
19- pub name : String ,
18+ #[ sort_key]
19+ pub sk : String ,
2020
2121 #[ cryptonamo( plaintext) ]
2222 pub tag : String ,
23-
24- #[ cryptonamo( skip) ]
25- pub temp : bool ,
2623}
2724
2825impl User {
2926 pub fn new ( email : impl Into < String > , name : impl Into < String > , tag : impl Into < String > ) -> Self {
3027 Self {
31- name : name. into ( ) ,
3228 pk : email. into ( ) ,
29+ sk : name. into ( ) ,
3330 tag : tag. into ( ) ,
34- temp : false ,
3531 }
3632 }
3733}
@@ -44,7 +40,7 @@ async fn run_test<F: Future<Output = ()>>(mut f: impl FnMut(EncryptedTable) -> F
4440
4541 let client = aws_sdk_dynamodb:: Client :: new ( & config) ;
4642
47- let table_name = "test -users" ;
43+ let table_name = "pk-sk -users" ;
4844
4945 common:: create_table ( & client, table_name) . await ;
5046
@@ -95,7 +91,7 @@ async fn test_query_single_prefix() {
9591 run_test ( |table| async move {
9692 let res: Vec < User > = table
9793 . query ( )
98- . starts_with ( "name " , "Dan" )
94+ . starts_with ( "sk " , "Dan" )
9995 . send ( )
10096 . await
10197 . expect ( "Failed to query" )
@@ -120,7 +116,7 @@ async fn test_query_compound() {
120116 run_test ( |table| async move {
121117 let res: Vec < User > = table
122118 . query ( )
123- . starts_with ( "name " , "Dan" )
119+ . starts_with ( "sk " , "Dan" )
124120125121 . send ( )
126122 . await
@@ -138,7 +134,10 @@ async fn test_query_compound() {
138134#[ serial]
139135async fn test_get_by_partition_key ( ) {
140136 run_test ( |table| async move {
141- let res
: Option < User > = table
. get ( "[email protected] " ) . await . expect ( "Failed to send" ) ; 137+ let res: Option < User > = table
138+ . get ( ( "[email protected] " , "Dan Draper" ) ) 139+ . await
140+ . expect ( "Failed to send" ) ;
142141 assert_eq ! (
143142 res,
144143 Some ( User :: new
( "[email protected] " , "Dan Draper" , "blue" ) ) @@ -152,19 +151,19 @@ async fn test_get_by_partition_key() {
152151async fn test_delete ( ) {
153152 run_test ( |table| async move {
154153 table
155- . delete :: < User > ( "[email protected] " ) 154+ . delete :: < User > ( ( "[email protected] " , "Dan Draper" ) ) 156155 . await
157156 . expect ( "Failed to send" ) ;
158157
159158 let res = table
160- 159+ . get :: < User > ( ( "[email protected] " , "Dan Draper" ) ) 161160 . await
162161 . expect ( "Failed to send" ) ;
163162 assert_eq ! ( res, None ) ;
164163
165164 let res = table
166165 . query :: < User > ( )
167- . starts_with ( "name " , "Dan" )
166+ . starts_with ( "sk " , "Dan" )
168167 . send ( )
169168 . await
170169 . expect ( "Failed to send" ) ;
@@ -184,7 +183,7 @@ async fn test_delete() {
184183 let res = table
185184 . query :: < User > ( )
186185187- . starts_with ( "name " , "Dan" )
186+ . starts_with ( "sk " , "Dan" )
188187 . send ( )
189188 . await
190189 . expect ( "Failed to send" ) ;
0 commit comments