Simple Rust Application for YugabyteDB

Overview

Simple Rust Application for YugabyteDB

This application connects to your YugabyteDB instance via the Rust driver for PostgreSQL and performs basic SQL operations. The instructions below are provided for Yugabyte Cloud deployments. If you use a different type of deployment, then update the src/sample-app.rs file with proper connection parameters.

Prerequisite

  • Rust development environment. The sample application was created for Rust 1.58 but should work for earlier and later versions.
  • Command line tool or your favourite IDE, such as Visual Studio Code.

Start Yugabyte Cloud Cluster

Clone Application Repository

Clone the repository and change dirs into it:

git clone https://github.com/yugabyte/yugabyte-simple-rust-app && cd yugabyte-simple-rust-app

Provide Yugabyte Cloud Connection Parameters

Update the following connection parameters in the src/sample-app.rs file:

  • HOST - the hostname of your Yugabyte Cloud instance.
  • USER - the username for your instance.
  • PASSWORD - the database password.
  • SSL_MODE - make sure it's set to SslMode::Require.
  • 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 Yugabyte Cloud dashboard:

image

Run the Application

Build and run the application:

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:

>>>> 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 Yugabyte Cloud.

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, or raise a question on StackOverflow and tag the question with yugabytedb!

You might also like...
A simple tomasulo simulator written in Rust for the course Computer Architecture.
A simple tomasulo simulator written in Rust for the course Computer Architecture.

Tomasulo Simulator This is a Tomasulo simulator written in Rust for the course Computer Architecture. Two Demo programs are tested in the simulator, w

Simple and flexible queue implementation for Rust with support for multiple backends (Redis, RabbitMQ, SQS, etc.)

Omniqueue Omniqueue is an abstraction layer over queue backends for Rust. It includes support for RabbitMQ, Redis streams, and SQS out of the box. The

This is a small demo of how to transform a simple single-server RocksDB service written in Rust into a distributed version using OmniPaxos.

OmniPaxos Demo This is a small demo of how to transform a simple single-server RocksDB service into a distributed version using OmniPaxos. Related res

Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.
Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.

Description Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLit

Simple document-based NoSQL DBMS from scratch

cudb (a.k.a. cuda++) Simple document-based noSQL DBMS modelled after MongoDB. (Has nothing to do with CUDA, has a lot to do with the Cooper Union and

Simple crate that wraps a tokio::process into a tokio::stream

tokio-process-stream tokio-process-stream is a simple crate that wraps a tokio::process into a tokio::stream Having a stream interface to processes is

webmention-receiver - a simple program that receives webmentions, records them to a SQLite database

webmention-receiver is a simple program that receives webmentions, records them to a SQLite database, and allows viewing them via a webpage or RSS feed. It has no conception of an "account", and by default will accept webmentions for any domain. It is possible to configure it to only accept webmentions for a specific set of domains, if you'd prefer.

A simple library for Firebase real-time database

Firerust A very simple library to implement the Firebase real-time database in your code with the best performance Instalation Add this to your Cargo.

Plugin for macro-, mini-quad (quads) to save data in simple local storage using Web Storage API in WASM and local file on a native platforms.

quad-storage This is the crate to save data in persistent local storage in miniquad/macroquad environment. In WASM the data persists even if tab or br

Owner
yugabyte
The high-performance distributed SQL database for global, internet-scale apps.
yugabyte
Materialize simplifies application development with streaming data. Incrementally-updated materialized views - in PostgreSQL and in real time. Materialize is powered by Timely Dataflow.

Materialize is a streaming database for real-time applications. Get started Check out our getting started guide. About Materialize lets you ask questi

Materialize, Inc. 4.7k Jan 8, 2023
An explorer for the DeArrow database as a web application. Inspired by Lartza's SBrowser

DeArrow Browser An explorer for the DeArrow database as a web application. Inspired by Lartza's SBbrowser. Public instance available at dearrow.minibo

null 3 Aug 10, 2023
A simple key value database for storing simple structures.

Perdia-DB A simple key value database for storing simple structures. No nesting of structures is supported, but may be implemented in the future. Toke

Perdia 4 May 24, 2022
PickleDB-rs is a lightweight and simple key-value store. It is a Rust version for Python's PickleDB

PickleDB PickleDB is a lightweight and simple key-value store written in Rust, heavily inspired by Python's PickleDB PickleDB is fun and easy to use u

null 155 Jan 5, 2023
Simple, async embedded Rust

Cntrlr - Simple, asynchronous embedded Cntrlr is an all-in-one embedded platform for writing simple asynchronous applications on top of common hobbyis

Branan Riley 11 Jun 3, 2021
PackDb is a simple messagepack based database in rust

PackDb is a simple key value messagepack store Inspired by kwik It uses your local storage

Tricked 2 Apr 1, 2022
rust-mysql-simple support library for the r2d2 connection pool

r2d2-mysql rust-mysql-simple support library for the r2d2 connection pool.

outersky 44 Nov 1, 2022
Build SQLite virtual file systems (VFS) by implementing a simple Rust trait.

sqlite-vfs Build SQLite virtual file systems (VFS) by implementing a simple Rust trait. Documentation | Example This library is build for my own use-c

Markus Ast 56 Dec 19, 2022
A simple embedded key-value store written in rust as a learning project

A simple embedded key-value store written in rust as a learning project

Blobcode 1 Feb 20, 2022
A fast and simple in-memory database with a key-value data model written in Rust

Segment Segment is a simple & fast in-memory database with a key-value data model written in Rust. Features Dynamic keyspaces Keyspace level control o

Segment 61 Jan 5, 2023