-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced libpq pointers with safe unique ptrs
- Loading branch information
Showing
5 changed files
with
41 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <libpq-fe.h> | ||
|
||
#include <memory> | ||
#include <string_view> | ||
|
||
/// Just small wrappers around libpq types to not have to deal with freeing them | ||
/// manually. | ||
namespace async_postgres::pg { | ||
using conn = std::unique_ptr<PGconn, decltype(&PQfinish)>; | ||
using result = std::unique_ptr<PGresult, decltype(&PQclear)>; | ||
using notify = std::unique_ptr<PGnotify, decltype(&PQfreemem)>; | ||
|
||
inline conn connectStart(std::string_view conninfo) { | ||
return conn(PQconnectStart(conninfo.data()), &PQfinish); | ||
} | ||
|
||
inline result getResult(conn& conn) { | ||
return result(PQgetResult(conn.get()), &PQclear); | ||
} | ||
|
||
inline notify getNotify(conn& conn) { | ||
return notify(PQnotifies(conn.get()), &PQfreemem); | ||
} | ||
} // namespace async_postgres::pg |