{"id":49353751,"url":"https://github.com/leventkaragol/libcpp-pg-pool","last_synced_at":"2026-04-27T11:32:12.334Z","repository":{"id":258757597,"uuid":"875146425","full_name":"leventkaragol/libcpp-pg-pool","owner":"leventkaragol","description":"Thread-safe, high performance, PostgreSQL connection pooling library for C++ (17+)","archived":false,"fork":false,"pushed_at":"2024-10-20T15:41:43.000Z","size":25,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-17T00:37:35.060Z","etag":null,"topics":["connection","connection-management","connection-manager","connection-pool","connection-pooling","pg","pool","pooling","postgresql"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leventkaragol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-19T08:04:31.000Z","updated_at":"2024-10-20T15:38:48.000Z","dependencies_parsed_at":"2024-10-20T21:07:35.380Z","dependency_job_id":null,"html_url":"https://github.com/leventkaragol/libcpp-pg-pool","commit_stats":null,"previous_names":["leventkaragol/libcpp-pg-pool"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/leventkaragol/libcpp-pg-pool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leventkaragol%2Flibcpp-pg-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leventkaragol%2Flibcpp-pg-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leventkaragol%2Flibcpp-pg-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leventkaragol%2Flibcpp-pg-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leventkaragol","download_url":"https://codeload.github.com/leventkaragol/libcpp-pg-pool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leventkaragol%2Flibcpp-pg-pool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32335296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connection","connection-management","connection-manager","connection-pool","connection-pooling","pg","pool","pooling","postgresql"],"created_at":"2026-04-27T11:32:11.441Z","updated_at":"2026-04-27T11:32:12.328Z","avatar_url":"https://github.com/leventkaragol.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libcpp-pg-pool\n\nThread-safe, high performance, PostgreSQL connection pooling library for C++ (17+)\n\n[![linux](https://github.com/leventkaragol/libcpp-pg-pool/actions/workflows/linux.yml/badge.svg)](https://github.com/leventkaragol/libcpp-pg-pool/actions/workflows/linux.yml)\n[![windows](https://github.com/leventkaragol/libcpp-pg-pool/actions/workflows/windows.yml/badge.svg)](https://github.com/leventkaragol/libcpp-pg-pool/actions/workflows/windows.yml)\n\n\n\u003e [!TIP]\n\u003e Please read this document before using the library. I know, you don't have time but reading\n\u003e this document will save you time. I mean just this file, it's not long at all. Trial and error\n\u003e will cost you more time.\n\n# Table of Contents\n\n* [How to add it to my project](#how-to-add-it-to-my-project)\n* [How to use? (Simple Connection)](#how-to-use-simple-connection)\n* [How to use? (Shared Connection)](#how-to-use-shared-connection)\n* [Semantic Versioning](#semantic-versioning)\n* [Full function list](#full-function-list)\n* [License](#license)\n* [Contact](#contact)\n\n## How to add it to my project?\n\nThis is a header only library. So actually, all you need is to add the libcpp-pg-pool.hpp file\nin src folder to your project and start using it with #include.\n\nBut this library is uses libpqxx under the hood. So, you also need to add libpqxx to\nyour project before to use it.\n\nYou can find usage examples in the examples folder, also find a sample CMakeLists.txt file content below.\n\n```cmake\ncmake_minimum_required(VERSION 3.14)\n\nproject(myProject)\n\nfind_package(libpqxx CONFIG REQUIRED)\n\nadd_executable(myProject main.cpp libcpp-pg-pool.hpp)\n\ntarget_link_libraries(myProject PRIVATE libpqxx::pqxx)\n\n```\n\n## How to use? (Simple Connection)\n\nYou can use the **\"acquire\"** method to obtain a new connection. The value returned from the acquire method\nis a shared pointer and the connection is automatically returned to the pool as soon as it goes out of scope.\nTherefore, you do not need to close the connection manually.\n\n\u003e [!IMPORTANT]\n\u003e Connection Pool should be created only once in the application\n\u003e It may take up to 1 second to be ready depending on the pool size\n\n```cpp\n#include \"libcpp-pg-pool.hpp\"\n\nusing namespace lklibs;\n\nint main() {\n\n    const auto connectionString = \"dbname=my_db user=my_user password=my_password host=localhost port=5432\";\n\n    // You can optionally specify the connection pool size, but if you don't, the default value will be 100\n    PgPool pool(connectionString, 10);\n\n\n    {\n        // Acquire a connection from the pool\n        const auto dbConnection = pool.acquire();\n\n        pqxx::work txn(*dbConnection);\n\n        const auto result = txn.exec(\"SELECT * FROM my_table\");\n\n        for (const auto\u0026 row : result)\n        {\n            std::cout \u003c\u003c row[0].c_str() \u003c\u003c std::endl;\n        }\n    }\n\n    // Connection is automatically returned to the pool when the dbConnection goes out of scope\n    // So, no need to manually close the connection\n\n    return 0;\n}\n```\n\n\u003e [!IMPORTANT]\n\u003e The connection pool size should not exceed PostgreSQL's max_connections limit,\n\u003e otherwise you will get an error like \"too many clients\"\n\n## How to use? (Shared Connection)\n\nThe return value from the acquire method is a shared pointer and counts shared references. When you open a connection\nand share it with another class, even if the acquired connection object goes out of scope, it keeps the connection open\nuntil the last shared class object is destroyed.\n\n```cpp\n#include \"libcpp-pg-pool.hpp\"\n\nusing namespace lklibs;\n\nclass SampleConsumer\n{\npublic:\n    void setDbConnection(std::shared_ptr\u003cpqxx::connection\u003e dbConnection)\n    {\n        this-\u003edbConnection = std::move(dbConnection);\n    }\n\n    void queryData() const\n    {\n        pqxx::work txn(*dbConnection);\n\n        const auto result = txn.exec(\"SELECT * FROM my_table\");\n\n        for (const auto\u0026 row : result)\n        {\n            std::cout \u003c\u003c row[0].c_str() \u003c\u003c std::endl;\n        }\n    }\n\n    [[nodiscard]] bool isConnectionOpen() const\n    {\n        return dbConnection-\u003eis_open();\n    }\n\nprivate:\n    std::shared_ptr\u003cpqxx::connection\u003e dbConnection;\n};\n\nint main() {\n\n    const auto connectionString = \"dbname=my_db user=my_user password=my_password host=localhost port=5432\";\n\n    PgPool pool(connectionString);\n\n\n    {\n        SampleConsumer myConsumer{};\n\n        {\n            // Acquire a connection from the pool\n            const auto dbConnection = pool.acquire();\n\n            // Connection is shared with SampleConsumer\n            myConsumer.setDbConnection(dbConnection);\n\n            myConsumer.queryData();\n        }\n\n        // Connection is still alive even after the dbConnection goes out of scope because SampleConsumer is still holding the shared_ptr\n\n        std::cout \u003c\u003c \"Connection status:\" \u003c\u003c myConsumer.isConnectionOpen() \u003c\u003c std::endl;\n    }\n\n    // Connection is automatically returned to the pool when all shared_ptr holding the connection go out of scope\n\n    return 0;\n```\n\n## Semantic Versioning\n\nVersioning of the library is done using conventional semantic versioning. Accordingly,\nin the versioning made as **MAJOR.MINOR.PATCH**;\n\n**PATCH:** Includes possible Bug\u0026Fixes and improvements. You definitely want to get this.\n\n**MINOR:** Additional functionality added via backwards compatibility. You probably want to\nget this, it doesn't hurt.\n\n**MAJOR:** Additional functionality that breaks backwards compatibility. You'll need to know\nwhat's changed before you get it, and you'll probably have to make changes to your own code.\nIf I publish something like this, I will definitely add the changes required for migration\nsection to the documentation.\n\n## Full function list\n\nYou can find the complete list of functions in the library below.\n\n\u003e [!TIP]\n\u003e All functions and parameters descriptions are also available within the code as comment for IDEs.\n\n```cpp\nstd::shared_ptr\u003cpqxx::connection\u003e acquire();\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2024 Levent KARAGÖL\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n## Contact\n\nIf you have problems regarding the library, please open an\n[issue on GitHub](https://github.com/leventkaragol/libcpp-pg-pool/issues/new).\nPlease describe your request, issue, or question in as much detail as possible\nand also include the version of your compiler and operating system, as well as\nthe version of the library you are using. Before opening a new issue, please\nconfirm that the topic is not already exists in closed issues.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleventkaragol%2Flibcpp-pg-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleventkaragol%2Flibcpp-pg-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleventkaragol%2Flibcpp-pg-pool/lists"}