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
57
58
59
60
61
62
63
64
65
66
67
68
69
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
pub use postgres::Client;
use postgres_openssl::MakeTlsConnector;
pub use postgres;
pub fn postgres_client(database_url: &str) -> Client {
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
builder.set_verify(SslVerifyMode::NONE);
let connector = MakeTlsConnector::new(builder.build());
Client::connect(
database_url,
connector,
).unwrap()
}
pub fn postgres_smoke_test(client: &mut Client) {
client.simple_query("
CREATE TABLE IF NOT EXISTS person_nonconflicting (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
data BYTEA
)
").unwrap();
let name = "Ferris";
let data = None::<&[u8]>;
client.execute(
"INSERT INTO person_nonconflicting (name, data) VALUES ($1, $2)",
&[&name, &data],
).unwrap();
for row in client.query("SELECT id, name, data FROM person_nonconflicting", &[]).unwrap() {
let id: i32 = row.get(0);
let name: &str = row.get(1);
let data: Option<&[u8]> = row.get(2);
println!("found person_nonconflicting: {} {} {:?}", id, name, data);
}
client.simple_query("DROP TABLE person_nonconflicting").unwrap();
}