query_opt test

This commit is contained in:
Steven Fackler 2019-12-10 16:34:04 -08:00
parent bf8b335d2b
commit 4a5a277878

View File

@ -667,11 +667,11 @@ async fn query_one() {
client
.batch_execute(
"
CREATE TEMPORARY TABLE foo (
name TEXT
);
INSERT INTO foo (name) VALUES ('alice'), ('bob'), ('carol');
",
CREATE TEMPORARY TABLE foo (
name TEXT
);
INSERT INTO foo (name) VALUES ('alice'), ('bob'), ('carol');
",
)
.await
.unwrap();
@ -691,3 +691,36 @@ async fn query_one() {
.err()
.unwrap();
}
#[tokio::test]
async fn query_opt() {
let client = connect("user=postgres").await;
client
.batch_execute(
"
CREATE TEMPORARY TABLE foo (
name TEXT
);
INSERT INTO foo (name) VALUES ('alice'), ('bob'), ('carol');
",
)
.await
.unwrap();
assert!(client
.query_opt("SELECT * FROM foo WHERE name = 'dave'", &[])
.await
.unwrap()
.is_none());
client
.query_opt("SELECT * FROM foo WHERE name = 'alice'", &[])
.await
.unwrap()
.unwrap();
client
.query_one("SELECT * FROM foo", &[])
.await
.err()
.unwrap();
}