-
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.
- Loading branch information
Showing
10 changed files
with
220 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
#pragma once | ||
|
||
#include <pfr-orm/definitions.hpp> | ||
|
||
#include <libpq-fe.h> | ||
#include <pfr-orm/postgres/utils.hpp> | ||
|
||
namespace pfrorm::postgres::detail { | ||
|
||
void createTable(PGconn &connection, const EntityDescription &entity); | ||
void createTable(Connection &connection, const EntityDescription &entity); | ||
|
||
bool exists(PGconn &connection, const EntityDescription &entity); | ||
bool exists(Connection &connection, const EntityDescription &entity); | ||
|
||
} // namespace pfrorm::postgres::detail |
This file was deleted.
Oops, something went wrong.
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,96 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <string_view> | ||
|
||
struct pg_conn; | ||
struct pg_result; | ||
|
||
namespace pfrorm::postgres { | ||
|
||
class Str { | ||
public: | ||
Str(char *str) : str(str) {} | ||
~Str(); | ||
|
||
[[nodiscard]] std::string_view view() const { return str; } | ||
operator std::string_view() const { return str; } | ||
|
||
Str(const Str &) = delete; | ||
Str(Str &&) = delete; | ||
Str &operator=(const Str &) = delete; | ||
Str &operator=(Str &&) = delete; | ||
|
||
private: | ||
char *str; | ||
}; | ||
|
||
class Result { | ||
public: | ||
Result(pg_result *result) : result(result) {} | ||
~Result(); | ||
|
||
[[nodiscard]] int status() const; | ||
[[nodiscard]] std::string_view value(int row, int column) const; | ||
|
||
Result(const Result &) = delete; | ||
Result(Result &&) noexcept; | ||
Result &operator=(const Result &) = delete; | ||
Result &operator=(Result &&) = delete; | ||
|
||
private: | ||
pg_result *result; | ||
}; | ||
|
||
class Connection { | ||
public: | ||
Connection(const std::string &connectionStr); | ||
~Connection(); | ||
|
||
Connection(const Connection &) = delete; | ||
Connection(Connection &&) noexcept; | ||
Connection &operator=(const Connection &) = delete; | ||
Connection &operator=(Connection &&) = delete; | ||
|
||
[[nodiscard]] Str escapeIdentifier(std::string_view identifier) const; | ||
|
||
Result execute(const std::string &statement); | ||
|
||
Result query(const std::string &statement); | ||
|
||
private: | ||
pg_conn *connection; | ||
}; | ||
|
||
struct ParameterTraits { | ||
struct Parameter { | ||
std::string data; | ||
bool isBinary; // TODO: pass everything as binary | ||
}; | ||
|
||
template <typename T> static Parameter toParam(const T &value) = delete; | ||
}; | ||
|
||
template <> | ||
inline ParameterTraits::Parameter | ||
ParameterTraits::toParam(const uint64_t &value) { | ||
return { | ||
.data = std::to_string(value), | ||
.isBinary = false, | ||
}; | ||
} | ||
|
||
template <> | ||
inline ParameterTraits::Parameter | ||
ParameterTraits::toParam(const std::string &value) { | ||
return { | ||
.data = value, | ||
.isBinary = true, | ||
}; | ||
} | ||
|
||
template <typename T> | ||
concept AsParameter = requires { ParameterTraits::toParam<T>; }; | ||
|
||
} // namespace pfrorm::postgres |
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,18 @@ | ||
#pragma once | ||
|
||
#include <pfr-orm/postgres/utils.hpp> | ||
|
||
#include <string_view> | ||
|
||
#include <fmt/core.h> | ||
#include <fmt/format.h> | ||
|
||
template <> | ||
struct fmt::formatter<pfrorm::postgres::Str> : formatter<std::string_view> { | ||
public: | ||
template <typename FormatContext> | ||
constexpr auto format(const pfrorm::postgres::Str &str, | ||
FormatContext &ctx) const -> decltype(ctx.out()) { | ||
return formatter<std::string_view>::format(str.view(), ctx); | ||
} | ||
}; |
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
Oops, something went wrong.