{"id":21042690,"url":"https://github.com/yugabytedb-samples/yugabyte-simple-cpp-app","last_synced_at":"2026-01-04T03:40:27.410Z","repository":{"id":69256341,"uuid":"457390477","full_name":"YugabyteDB-Samples/yugabyte-simple-cpp-app","owner":"YugabyteDB-Samples","description":"A simple C++ application that connects to a YugabyteDB database cluster and performs basic CRUD operations.","archived":false,"fork":false,"pushed_at":"2024-07-16T16:30:58.000Z","size":200,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":64,"default_branch":"main","last_synced_at":"2024-07-16T20:25:50.685Z","etag":null,"topics":["demos"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YugabyteDB-Samples.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":"2022-02-09T14:22:25.000Z","updated_at":"2024-07-16T16:31:01.000Z","dependencies_parsed_at":"2024-01-08T07:21:45.524Z","dependency_job_id":null,"html_url":"https://github.com/YugabyteDB-Samples/yugabyte-simple-cpp-app","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-cpp-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-cpp-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-cpp-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-cpp-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YugabyteDB-Samples","download_url":"https://codeload.github.com/YugabyteDB-Samples/yugabyte-simple-cpp-app/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225365976,"owners_count":17462973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["demos"],"created_at":"2024-11-19T14:08:40.977Z","updated_at":"2026-01-04T03:40:27.369Z","avatar_url":"https://github.com/YugabyteDB-Samples.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple C++ Application for YugabyteDB\n\nThis application connects to your YugabyteDB instance via the \n[libpqxx](http://pqxx.org/development/libpqxx/) driver for PostgreSQL and performs basic SQL \noperations. The instructions below are provided for [YugabyteDB Aeon](https://cloud.yugabyte.com/) deployments. \nIf you use a different type of deployment, then update the `sample-app.cpp` file with proper connection parameters.\n\n## Prerequisites\n\n* A 32-bit (x86) or 64-bit (x64) architecture machine. Use [Rosetta](https://support.apple.com/en-us/HT211861) to build and run on Apple silicon.\n* gcc 4.1.2 or later, clang 3.4 or later installed.\n* OpenSSL 1.1.1 or later (used by libpq and libpqxx to establish secure SSL connections).\n* [libpq](https://docs.yugabyte.com/latest/reference/drivers/ysql-client-drivers/#libpq) - the official PostgreSQL driver for C (reused by libpqxx).\n* [libpqxx](https://docs.yugabyte.com/latest/reference/drivers/ysql-client-drivers/#libpqxx) - the official PostgreSQL driver for C++.\n* Command line tool or your favourite IDE, such as Visual Studio Code.\n\n## Start YugabyteDB Aeon Cluster\n\n* [Start YugabyteDB Aeon](https://docs.yugabyte.com/latest/yugabyte-cloud/cloud-quickstart/qs-add/) instance. You can use\nthe free tier at no cost.\n* Add an IP address of your machine/laptop to the [IP allow list](https://docs.yugabyte.com/latest/yugabyte-cloud/cloud-secure-clusters/add-connections/#manage-ip-allow-lists)\n\n## Clone Application Repository\n\nClone the repository and change dirs into it:\n\n```bash\ngit clone https://github.com/YugabyteDB-Samples/yugabyte-simple-cpp-app.git \u0026\u0026 cd yugabyte-simple-cpp-app\n```\n\n## Provide Cluster Connection Parameters\n\nOpen the `sample-app.cpp` file and specify the following configuration parameters:\n* `HOST` - the hostname of your instance.\n* `USER` - the username for your instance.\n* `PASSWORD` - the database password.\n* `SSL_MODE` - the SSL mode to use. YugabyteDB Aeon requires SSL connections; use `verify-full`.\n* `SSL_ROOT_CERT` - a full path to your CA root cert (for example, `/Users/dmagda/certificates/root.crt`). \n\nNote, you can easily find all the settings on the YugabyteDB Aeon dashboard:\n\n![image](resources/cloud_app_settings.png)\n\n## Run the Application\n\n1. Install the [libpq](https://docs.yugabyte.com/latest/reference/drivers/ysql-client-drivers/#libpq) driver:\n    * Homebrew users can install using the `brew install libpq` command (find details [here](https://formulae.brew.sh/formula/libpq)).\n    * Others can download the PostgreSQL binaries and source from the [PostgreSQL Downloads](https://www.postgresql.org/download/) page.\n2. Install the [libpqxx](https://docs.yugabyte.com/latest/reference/drivers/ysql-client-drivers/#libpqxx) driver:\n    * Homebrew users can install using the `brew install libpqxx` command (find details [here](https://formulae.brew.sh/formula/libpqxx)).\n    * Others can build the driver using one of the options listed in the [Building libpqxx](https://github.com/jtv/libpqxx#building-libpqxx) section.\n    \n3. Build the application after replacing `{path-to-libpq}` and `{path-to-libpqxx}` with the paths to the libpq and libpqxx installations (for example, `/usr/local/opt`):\n    ```bash\n    g++ -std=c++17 sample-app.cpp -o sample-app -lpqxx -lpq \\\n    -I{path-to-libpq}/libpq/include -I{path-to-libpqxx}/libpqxx/include \\\n    -L{path-to-libpq}/libpq/lib -L{path-to-libpqxx}/libpqxx/lib \n    ```\n4. Run the application:\n    ```bash\n    ./sample-app\n    ```\n\nUpon successful execution, you will see output similar to the following:\n\n```bash\n\u003e\u003e\u003e\u003e Connecting to YugabyteDB!\n\u003e\u003e\u003e\u003e Successfully connected to YugabyteDB!\n\u003e\u003e\u003e\u003e Successfully created table DemoAccount.\n\u003e\u003e\u003e\u003e Selecting accounts:\nname=Jessica, age=28, country=USA, balance=10000\nname=John, age=28, country=Canada, balance=9000\n\u003e\u003e\u003e\u003e Transferred 800 between accounts.\n\u003e\u003e\u003e\u003e Selecting accounts:\nname=Jessica, age=28, country=USA, balance=9200\nname=John, age=28, country=Canada, balance=9800\n```\n\n## Explore Application Logic\n\nCongrats! You've successfully executed a simple C++ app that works with YugabyteDB.\n\nNow, explore the source code of `sample-app.cpp`:\n1. `connect` function - establishes a connection with your cloud instance via the libpqxx driver.\n2. `createDatabase` function - creates a table and populates it with sample data.\n3. `selectAccounts` function - queries the data with SQL `SELECT` statements.\n4. `transferMoneyBetweenAccounts` function - updates records consistently with distributed transactions.\n\n## Questions or Issues?\n\nHaving issues running this application or want to learn more from Yugabyte experts?\n\nJoin [our Slack channel](https://communityinviter.com/apps/yugabyte-db/register),\nor raise a question on StackOverflow and tag the question with `yugabytedb`!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-cpp-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-cpp-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-cpp-app/lists"}