{"id":21042688,"url":"https://github.com/yugabytedb-samples/yugabyte-simple-ruby-app","last_synced_at":"2025-07-31T23:33:56.237Z","repository":{"id":69256360,"uuid":"459193742","full_name":"YugabyteDB-Samples/yugabyte-simple-ruby-app","owner":"YugabyteDB-Samples","description":"A simple Ruby application that connects to a YugabyteDB database cluster and performs basic CRUD operations.","archived":false,"fork":false,"pushed_at":"2024-07-16T16:33:08.000Z","size":149,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":61,"default_branch":"main","last_synced_at":"2025-02-28T14:06:31.106Z","etag":null,"topics":["demos","ruby","yugabytedb"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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-14T14:24:44.000Z","updated_at":"2024-07-16T16:33:11.000Z","dependencies_parsed_at":"2023-09-15T11:45:14.014Z","dependency_job_id":null,"html_url":"https://github.com/YugabyteDB-Samples/yugabyte-simple-ruby-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-ruby-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-ruby-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-ruby-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fyugabyte-simple-ruby-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-ruby-app/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243489780,"owners_count":20298997,"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","ruby","yugabytedb"],"created_at":"2024-11-19T14:08:40.915Z","updated_at":"2025-03-13T21:43:06.304Z","avatar_url":"https://github.com/YugabyteDB-Samples.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Ruby Application for YugabyteDB\n\nThis application connects to your YugabyteDB instance via the \n[Ruby Pg](https://github.com/ged/ruby-pg) driver for PostgreSQL and performs basic SQL operations. 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.rb` file with proper connection parameters.\n\n## Prerequisites\n\n* Ruby 3.1 or later.\n* OpenSSL 1.1.1 or later (used by libpq and Ruby Pg to establish SSL connections).\n* [libpq](https://docs.yugabyte.com/latest/reference/drivers/ysql-client-drivers/#libpq) - the official PostgreSQL driver for C (required by Ruby Pg).\n* [Ruby Pg](https://github.com/ged/ruby-pg) - the official Ruby driver for PostgreSQL.\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-ruby-app.git \u0026\u0026 cd yugabyte-simple-ruby-app\n```\n\n## Provide Cluster Connection Parameters\n\nLocate and define the following connection parameters in the `sample-app.rb` file:\n* `host` - the hostname of your instance.\n* `user` - the username for your database.\n* `password` - the password for your database.\n* `sslmode`  - an SSL mode. Make sure it's set to `verify-full` for YugabyteDB Aeon.\n* `sslrootcert` - 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 (required by Ruby Pg):\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.\n\n2. Replace `{path-to-libpq}` with the path to the libpq installation and install [Ruby Pg](https://github.com/ged/ruby-pg):\n    ```bash\n    gem install pg -- --with-pg-include={path-to-libpq}/libpq/include --with-pg-lib={path-to-libpq}/libpq/lib\n    ```\n\n    Find alternative installation instructions [here](https://github.com/ged/ruby-pg#label-How+To+Install).\n\n4. Make the application file executable:\n    ```bash\n    chmod +x sample-app.rb\n    ```\n\n3. Run the application:\n    ```bash\n    ./sample-app.rb\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 Ruby app that works with YugabyteDB.\n\nNow, explore the source code of `sample-app.rb`:\n1. `connect` function - establishes a connection with your cloud instance via the Ruby Pg driver.\n2. `create_database` function - creates a table and populates it with sample data.\n3. `select_accounts` function - queries the data with SQL `SELECT` statements.\n4. `transfer_money_between_accounts` 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-ruby-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-ruby-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fyugabyte-simple-ruby-app/lists"}