-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathunchecked.rs
56 lines (47 loc) · 1.34 KB
/
unchecked.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
use rust_query::{
migration::{schema, Config},
Database, LocalClient,
};
#[schema]
enum Schema {
Name { name: String },
}
use v0::*;
fn main() {
// Get a LocalClient to prove that we have our own thread.
// This is necessary to keep transactions separated.
let mut client = LocalClient::try_new().unwrap();
let database: Database<Schema> = client
.migrator(Config::open_in_memory())
.expect("database version is before supported versions")
// migrations go here
.finish()
.expect("database version is after supported versions");
let mut txn = client.transaction_mut(&database);
let ids: Vec<_> = vec!["alpha", "bravo", "charlie", "delta"]
.into_iter()
.map(|name| txn.insert(Name { name }))
.collect();
let mut txn = txn.downgrade();
let raw_txn = txn.unchecked_transaction();
for id in ids {
let name: String = raw_txn
.query_row("select name from Name where id = $1", &[&id], |row| {
row.get(0)
})
.unwrap();
println!("{name}")
}
txn.commit();
}
#[test]
fn run() {
main();
}
#[test]
#[cfg(feature = "dev")]
fn schema_hash() {
use expect_test::expect;
use rust_query::migration::hash_schema;
expect!["822e0ab9b42056f7"].assert_eq(&hash_schema::<v0::Schema>());
}