Skip to content

Commit 7e50a47

Browse files
committed
protocol, query: Add limited dynamic list support
1 parent fa5638f commit 7e50a47

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/query.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)