-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdynamic_lists_simple.rs
41 lines (37 loc) · 1.26 KB
/
dynamic_lists_simple.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
assume the model is created using:
> create space myapp
> create model myapp.mydb(username: string, password: string, data: [string])
*/
use skytable::{query::QList, response::RList, Config};
fn get_list_data_from_api() -> Vec<String> {
vec![
"stuff".to_owned(),
"from".to_owned(),
"the".to_owned(),
"api".to_owned(),
]
}
fn main() {
let mut db = Config::new_default("root", "password12345678")
.connect()
.unwrap();
let data_from_api = get_list_data_from_api();
let q = skytable::query!(
"insert into myapp.mydb { username: ?, password: ?, data: ? }",
"sayan",
"ulw06afuMCAg+1gh2lh1Y9xTIr/dUv2vqGLeZ39cVrE=",
QList::new(&data_from_api)
);
db.query_parse::<()>(&q).unwrap(); // expect this data to be inserted correctly
// now fetch this data
let (username, password, data): (String, String, RList<String>) = db
.query_parse(&skytable::query!(
"select * from myapp.mydb where username = ?",
"sayan"
))
.unwrap();
assert_eq!(username, "sayan");
assert_eq!(password, "ulw06afuMCAg+1gh2lh1Y9xTIr/dUv2vqGLeZ39cVrE=");
assert_eq!(data.into_values(), data_from_api);
}