File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -390,3 +390,42 @@ impl SQParam for String {
390390 self . as_str ( ) . append_param ( buf)
391391 }
392392}
393+
394+ const LIST_SYM_OPEN : u8 = 0x09 ;
395+ const LIST_SYM_CLOSE : u8 = ']' as u8 ;
396+
397+ /// A list type representing a Skyhash list type, used in parameter lists
398+ pub struct List < ' a , T : SQParam > {
399+ l : & ' a [ T ] ,
400+ }
401+
402+ impl < ' a , T : SQParam > List < ' a , T > {
403+ /// create a new list
404+ pub fn new ( l : & ' a [ T ] ) -> Self {
405+ Self { l }
406+ }
407+ }
408+
409+ impl < ' a , T : SQParam > SQParam for List < ' a , T > {
410+ fn append_param ( & self , q : & mut Vec < u8 > ) -> usize {
411+ q. push ( LIST_SYM_OPEN ) ;
412+ for param in self . l {
413+ param. append_param ( q) ;
414+ }
415+ q. push ( LIST_SYM_CLOSE ) ;
416+ 1
417+ }
418+ }
419+
420+ #[ test]
421+ fn list_param ( ) {
422+ let data = vec ! [ "hello" , "giant" , "world" ] ;
423+ let list = List :: new ( & data) ;
424+ let q = query ! (
425+ "insert into apps.social(?, ?, ?)" ,
426+ "username" ,
427+ "password" ,
428+ list
429+ ) ;
430+ assert_eq ! ( q. param_cnt( ) , 3 ) ;
431+ }
You can’t perform that action at this time.
0 commit comments