Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yugabytedb-samples/yugabyte-simple-rust-app
A simple Rust application that connects to a YugabyteDB database cluster and performs basic CRUD operations.
https://github.com/yugabytedb-samples/yugabyte-simple-rust-app
demos rust yugabytedb
Last synced: about 7 hours ago
JSON representation
A simple Rust application that connects to a YugabyteDB database cluster and performs basic CRUD operations.
- Host: GitHub
- URL: https://github.com/yugabytedb-samples/yugabyte-simple-rust-app
- Owner: YugabyteDB-Samples
- License: apache-2.0
- Created: 2022-02-15T16:08:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-16T16:34:15.000Z (4 months ago)
- Last Synced: 2024-07-16T20:29:21.795Z (4 months ago)
- Topics: demos, rust, yugabytedb
- Language: Rust
- Homepage:
- Size: 192 KB
- Stars: 1
- Watchers: 65
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple Rust Application for YugabyteDB
This application connects to your YugabyteDB instance via the
[Rust](https://github.com/sfackler/rust-postgres) driver for PostgreSQL and performs basic SQL operations. The instructions below are provided for [YugabyteDB Aeon](https://cloud.yugabyte.com/) deployments.
If you use a different type of deployment, then update the `src/sample-app.rs` file with proper connection parameters.## Prerequisite
* [Rust](https://www.rust-lang.org/tools/install) development environment. The sample application was created for Rust 1.58 but should work for earlier and later versions.
* Command line tool or your favorite IDE, such as Visual Studio Code.## Start YugabyteDB Aeon Cluster
* [Start YugabyteDB Aeon](https://docs.yugabyte.com/latest/yugabyte-cloud/cloud-quickstart/qs-add/) instance. You can use
the free tier at no cost.
* 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)## Clone Application Repository
Clone the repository and change dirs into it:
```bash
git clone https://github.com/YugabyteDB-Samples/yugabyte-simple-rust-app.git && cd yugabyte-simple-rust-app
```## Provide Cluster Connection Parameters
Update the following connection parameters in the `src/sample-app.rs` file:
* `HOST` - the hostname of your instance.
* `USER` - the username for your instance.
* `PASSWORD` - the database password.
* `SSL_MODE` - make sure it's set to `SslMode::Require` for YugabyteDB Aeon.
* `SSL_ROOT_CERT` - a full path to your CA root cert (for example, `/Users/dmagda/certificates/root.crt`).Note, you can easily find all the settings on the YugabyteDB Aeon dashboard:
![image](resources/cloud_app_settings.png)
## Run the Application
Build and run the application:
```bash
cargo run
```The Rust PostgreSQL driver will be installed automatically during the first execution of the command. The driver is listed in the dependencies list of the `Cargo.toml` file.
Upon successful execution, you will see output similar to the following:
```bash
>>>> Connecting to YugabyteDB!
>>>> Successfully connected to YugabyteDB!
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 10000
name = John, age = 28, country = Canada, balance = 9000
>>>> Transferred 800 between accounts
>>>> Selecting accounts:
name = Jessica, age = 28, country = USA, balance = 9200
name = John, age = 28, country = Canada, balance = 9800
```## Explore Application Logic
Congrats! You've successfully executed a simple Rust app that works with YugabyteDB.
Now, explore the source code of `src/sample-app.rs`:
1. `connect` function - establishes a connection with your cloud instance via the Rust PostgreSQL driver.
2. `create_database` function - creates a table and populates it with sample data.
3. `select_accounts` function - queries the data with SQL `SELECT` statements.
4. `transfer_money_between_accounts` function - updates records consistently with distributed transactions.## Questions or Issues?
Having issues running this application or want to learn more from Yugabyte experts?
Join [our Slack channel](https://communityinviter.com/apps/yugabyte-db/register),
or raise a question on StackOverflow and tag the question with `yugabytedb`!