Skip to content

Commit 79dc3aa

Browse files
committed
cleanup
1 parent 6f1205a commit 79dc3aa

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

frameworks/Rust/khttp/src/main.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
33

44
use khttp::{Headers, Method::*, RequestContext, ResponseHandle, Server, Status};
5+
use pq_sys::{
6+
ConnStatusType, ExecStatusType, PGconn, PQclear, PQconnectdb, PQerrorMessage, PQexecPrepared,
7+
PQfinish, PQgetlength, PQgetvalue, PQntuples, PQprepare, PQresultStatus, PQstatus,
8+
};
59
use std::{ffi::CStr, io, ptr, sync::LazyLock};
610
use yarte::{Serialize, ywrite_html};
711

@@ -58,11 +62,6 @@ fn handle_fortunes(_ctx: RequestContext, res: &mut ResponseHandle) -> io::Result
5862
// /fortunes query implementation using postgres (libpq)
5963
// ---------------------------------------------------------------------
6064

61-
use pq_sys::{
62-
ConnStatusType, ExecStatusType, PGconn, PQclear, PQconnectdb, PQerrorMessage, PQexecPrepared,
63-
PQfinish, PQgetlength, PQgetvalue, PQntuples, PQprepare, PQresultStatus, PQstatus,
64-
};
65-
6665
const DB_CONNINFO: &CStr = c"postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world";
6766
const PG_FORTUNES_SQL: &CStr = c"SELECT id, message FROM fortune";
6867
const PG_FORTUNES_PREPARED_STMT: &CStr = c"s_fortunes";
@@ -73,7 +72,7 @@ struct Fortune<'a> {
7372
message: &'a str,
7473
}
7574

76-
fn fetch_fortunes_html() -> Result<Vec<u8>, String> {
75+
fn fetch_fortunes_html() -> Result<Vec<u8>, &'static str> {
7776
PG_CONN.with(|pg| unsafe {
7877
let res = PQexecPrepared(
7978
pg.conn,
@@ -85,11 +84,11 @@ fn fetch_fortunes_html() -> Result<Vec<u8>, String> {
8584
1, // resultFormat = 1 (binary)
8685
);
8786
if res.is_null() {
88-
return Err("PQexecPrepared returned null".to_owned());
87+
return Err("PQexecPrepared returned null");
8988
}
9089
if PQresultStatus(res) != ExecStatusType::PGRES_TUPLES_OK {
9190
PQclear(res);
92-
return Err("PQexecPrepared non-ok result status".to_owned());
91+
return Err("PQexecPrepared non-ok result status");
9392
}
9493

9594
let rows = PQntuples(res);
@@ -159,7 +158,6 @@ impl PgConnection {
159158
PQfinish(conn);
160159
panic!("PQprepare returned null");
161160
}
162-
163161
let st = PQresultStatus(res);
164162
PQclear(res);
165163
if st != ExecStatusType::PGRES_COMMAND_OK {

0 commit comments

Comments
 (0)