Npgsql Wrapper is a lightweight, high-performance C/C++ wrapper around the PostgreSQL client library (libpq), designed to simplify database interactions while maintaining efficiency and flexibility.
- Simple and clean API for PostgreSQL operations
- Secure parameterized queries
- Connection pooling for efficient resource management
- Asynchronous support for non-blocking operations
- Strongly-typed query results
- Lightweight and easy to integrate
- PostgreSQL client library (
libpq
) - C++17 or later
- CMake (for building the project)
git clone https://github.com/fsystech/npgsql_wrapper.git
cd npgsql_wrapper
mkdir build && cd build
cmake ..
make
sudo make install
#include "npgsql_wrapper.h"
int main() {
npgsql::Database db("host=myserver user=myuser password=mypass dbname=mydb");
if (!db.isConnected()) {
std::cerr << "Failed to connect to database" << std::endl;
return 1;
}
auto result = db.query("SELECT * FROM users WHERE id = $1", 1);
for (auto& row : result) {
std::cout << "User ID: " << row["id"].as<int>() << ", Name: " << row["name"].as<std::string>() << "\n";
}
return 0;
}
Database(const std::string& connectionString)
- Initializes the database connection.bool isConnected() const
- Checks if the connection is active.QueryResult query(const std::string& sql, Args... args)
- Executes a query with optional parameters.int execute(const std::string& sql, Args... args)
- Executes a non-query statement (INSERT, UPDATE, DELETE).
bool empty() const
- Checks if the result set is empty.size_t size() const
- Returns the number of rows.Row operator[](size_t index) const
- Access a specific row.
Column operator[](const std::string& columnName) const
- Access a specific column.template<typename T> T as() const
- Convert the column value to the desired type.
This project is licensed under the MIT License.
Contributions are welcome! Feel free to submit issues or pull requests to improve the Npgsql Wrapper.
For any inquiries, reach out to FSys Tech Ltd.