-
Notifications
You must be signed in to change notification settings - Fork 243
/
lib.rs
56 lines (49 loc) · 1.39 KB
/
lib.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
mod random_rowid;
mod virtual_wal;
#[cfg(all(test, feature = "udf"))]
mod user_defined_functions;
#[cfg(all(test, feature = "udf"))]
mod user_defined_functions_src;
#[cfg(test)]
mod tests {
use rusqlite::Connection;
#[derive(Debug, PartialEq)]
struct Person {
name: String,
data: Option<Vec<u8>>,
}
#[test]
fn test_insert_steven() {
let conn = Connection::open_in_memory().unwrap();
conn.execute(
"CREATE TABLE person (
name TEXT NOT NULL,
data BLOB
)",
(),
)
.unwrap();
let steven = Person {
name: "Steven".to_string(),
data: Some(vec![4, 2]),
};
conn.execute(
"INSERT INTO person (name, data) VALUES (?1, ?2)",
(&steven.name, &steven.data),
)
.unwrap();
let mut stmt = conn.prepare("SELECT name, data FROM person").unwrap();
let mut person_iter = stmt
.query_map([], |row| {
Ok(Person {
name: row.get(0).unwrap(),
data: row.get(1).unwrap(),
})
})
.unwrap();
let also_steven = person_iter.next().unwrap().unwrap();
println!("Read {:#?}", also_steven);
assert!(also_steven == steven);
assert!(person_iter.next().is_none())
}
}