forked from rust-postgres/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.rs
More file actions
28 lines (23 loc) · 732 Bytes
/
Copy pathtest.rs
File metadata and controls
28 lines (23 loc) · 732 Bytes
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
extern mod postgres;
use postgres::{PostgresConnection, PostgresRow};
macro_rules! chk(
($e:expr) => (
match $e {
Ok(ok) => ok,
Err(err) => fail!(err)
}
)
)
#[test]
fn test_conn() {
let conn = chk!(PostgresConnection::new("postgres://postgres@localhost"));
chk!(conn.update("DROP TABLE IF EXISTS foo"));
chk!(conn.update("CREATE TABLE foo (foo INT PRIMARY KEY)"));
chk!(conn.update("INSERT INTO foo (foo) VALUES (101)"));
let res = chk!(conn.query("SELECT foo from foo"));
assert_eq!(1, res.len());
let rows: ~[PostgresRow] = res.iter().collect();
assert_eq!(1, rows.len());
assert_eq!(1, rows[0].len());
assert_eq!(Some(101), rows[0][0]);
}