{"id":21042689,"url":"https://github.com/yugabytedb-samples/yugabyte-simple-c-app","last_synced_at":"2026-03-08T04:31:03.142Z","repository":{"id":69256319,"uuid":"456582339","full_name":"YugabyteDB-Samples/yugabyte-simple-c-app","owner":"YugabyteDB-Samples","description":"A simple C app that connects to a YugabyteDB database cluster and performs basic CRUD operations.","archived":false,"fork":false,"pushed_at":"2024-07-16T16:29:39.000Z","size":210,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":61,"default_branch":"main","last_synced_at":"2025-02-28T14:06:31.007Z","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-07T16:18:09.000Z","updated_at":"2024-07-16T16:29:42.000Z","dependencies_parsed_at":"2023-03-11T05:34:04.421Z","dependency_job_id":null,"html_url":"https://github.com/YugabyteDB-Samples/yugabyte-simple-c-app","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/YugabyteDB-Samples/yugabyte-simple-c-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-c-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-c-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-c-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-c-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-c-app/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-c-app/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30245212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"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":["demos"],"created_at":"2024-11-19T14:08:40.926Z","updated_at":"2026-03-08T04:31:03.084Z","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[libpq](https://docs.yugabyte.com/latest/reference/drivers/ysql-client-drivers/#libpq) driver 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.c` 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 the Apple silicon.\n* gcc 4.1.2 or later, clang 3.4 or later installed.\n* [libpq](https://docs.yugabyte.com/latest/reference/drivers/ysql-client-drivers/#libpq) driver.\n* OpenSSL library (used by libpq to establish secured SSL connections).\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-c-app.git \u0026\u0026 cd yugabyte-simple-c-app\n```\n\n## Provide Cluster Connection Parameters\n\nLocate and define the following configuration-related macros in the `sample-app.c` file:\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 driver via [Homebrew package manager](https://formulae.brew.sh/formula/libpq) or using a [different method](https://www.postgresql.org/download/).\n    \n2. Replace the `{libpq-install-dir}` placeholder with your libpq installation root dir and build the application with `gcc` or `clang`:\n    ```bash\n    gcc sample-app.c -o sample-app -I{libpq-install-dir}/libpq/include -L{libpq-install-dir}/libpq/lib -lpq\n    ```\n3. 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 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.c`:\n1. `connect` function - establishes a connection with your cloud instance via the libpq 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-c-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-c-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-c-app/lists"}