A user crud written in Rust, designed to connect to a MySQL database with full integration test coverage.

Overview

SQLX User CRUD

Purpose

This application demonstrates the how to implement a common design for CRUDs in, potentially, a system of microservices. The design pattern is akin to MVC (model, view, controller) minus the view. This type of application is commonly developed in languages like Java or C#, so the objective in its development has been to demonstrate a way to simply implement something familiar to C#'s DbContext that contains a DbSet<T> of each entity to be stored in the database.

Data Design

The database layout is simple, and illustrates a common relationship. The the database there are 3 tables: (1) Users (2) Groups and (3) UsersToGroups. Groups and Users have a many-to-many relationship. This many-to-many relationship also exists in the Rust application where a User has a Vec<Group>.

Application Design

The application itself has been designed with a modular approach. It is common for Rust projects (specifically for the purpose of demonstration) to consolidate code into only a handful of files. Dividing this project into multiple modules, and many small files was intentional, as it makes the overall architecture clear.

The architecture is that of a trivial crud. There are two key layers: (1) the Controller and (2) the DAO (Data Access Object). The controller layer organizes the interaction between the DAO and the incoming/outgoing HTTP. Based on the various DAO responses, specific HTTP responses are provided.

Test Coverage

This application uses an integration testing style to provided test coverage for all methods. Note, not all method paths are fully tested. All expected paths of behavior are tested. In a more comprehensive system, there would be reason to test all permutations of behavior. These test serve as an example for what is sufficient test coverage for an initial application.

Setup

First, have MySQL installed and running.

Next, run the schema.sql script. On Linux, this can be done in the terminal:

sudo mysql -u root < schema.sql

When schema.sql has executed successfully, run the tests:

cargo test

After the tests have completed and all pass, startup the application:

cargo run
You might also like...
A CRUD library for Holochain zomes that implements the CAPS pattern (Chained, Action ID, Permalink, State-based)

Holochain CRUD Library (CAPS pattern) A CRUD library for Holochain zomes that implement the CAPS pattern (Chained, Action, Permalink, State-based) Hol

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.

SQLx 🧰 The Rust SQL Toolkit Install | Usage | Docs Built with ❤️ by The LaunchBadge team SQLx is an async, pure Rust† SQL crate featuring compile-tim

Asyncronous Rust Mysql driver based on Tokio.

mysql-async Tokio based asynchronous MySql client library for rust programming language. Installation Library hosted on crates.io. [dependencies] mysq

Mysql client library implemented in rust.

mysql This crate offers: MySql database driver in pure rust; connection pool. Features: macOS, Windows and Linux support; TLS support via nativetls cr

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

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

This project provides a Rust-based solution for migrating MSSQL databases to MySQL.

MSSQL to MySQL Database Migration A Rust project to migrate MSSQL databases to MySQL, including table structures, column data types, and table data ro

A tool for automated migrations for PostgreSQL, SQLite and MySQL.

Models Models is an implementation for a SQL migration management tool. It supports PostgreSQL, MySQL, and SQLite. Quick Start install the CLI by runn

Gibbs MySQL Spyglass
Gibbs MySQL Spyglass

Gibbs MySQL Spyglass Ahoy Matey! The Gibbs MySQL Spyglass is a application used to capture application traffic into a MySQL database. It is designed t

fast & easy CLI and vscode extension specialized to format MySQL INSERT queries.
fast & easy CLI and vscode extension specialized to format MySQL INSERT queries.

insertfmt fast & easy CLI specialized to format MySQL INSERT queries. format queries so that they look like a table. NOTE: If you wanna use the VSCode

Comments
  • General upgrades

    General upgrades

    • [ ] 1. Rename the lifetimes.
    • [ ] 2. Strengthen types.
    • [ ] 2.1 Provide user password field.
    • [ ] 2.2 Regex email field
    • [ ] 3. Provide pagination for group focused queries: 1 get users by group (page u16) 2 get users by groups (p u8[0]... p u8[n]) 3 get groups of user
    • [ ] 4. Provide end-to-end tests via postman
    enhancement 
    opened by jamesjmeyer210 0
Owner
null
Grsql is a great tool to allow you set up your remote sqlite database as service and CRUD(create/read/update/delete) it using gRPC.

Grsql is a great tool to allow you set up your remote sqlite database as service and CRUD (create/ read/ update/ delete) it using gRPC. Why Create Thi

Bruce Yuan 33 Dec 16, 2022
cogo rust coroutine database driver (Mysql,Postgres,Sqlite)

cdbc Coroutine Database driver Connectivity.based on cogo High concurrency,based on coroutine No Future<'q,Output=*>,No async fn, No .await , no Poll*

co-rs 10 Nov 13, 2022
A Distributed SQL Database - Building the Database in the Public to Learn Database Internals

Table of Contents Overview Usage TODO MVCC in entangleDB SQL Query Execution in entangleDB entangleDB Raft Consensus Engine What I am trying to build

Sarthak Dalabehera 38 Jan 2, 2024
rust_arango enables you to connect with ArangoDB server, access to database, execute AQL query, manage ArangoDB in an easy and intuitive way, both async and plain synchronous code with any HTTP ecosystem you love.

rust_arango enables you to connect with ArangoDB server, access to database, execute AQL query, manage ArangoDB in an easy and intuitive way, both async and plain synchronous code with any HTTP ecosystem you love.

Foretag 3 Mar 24, 2022
ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-text search.

ReefDB ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-

Sacha Arbonel 75 Jun 12, 2023
A highly scalable MySQL Proxy framework written in Rust

mysql-proxy-rs An implementation of a MySQL proxy server built on top of tokio-core. Overview This crate provides a MySQL proxy server that you can ex

AgilData 175 Dec 19, 2022
Rust - Build a CRUD API with SQLX and PostgreSQL

In this article, you'll learn how to build a CRUD API in Rust using SQLX, Actix-web, and PostgreSQL. Learning how to build a CRUD API as a developer will equip you with valuable skills for building robust, maintainable, and scalable applications.

CODEVO 5 Feb 20, 2023
Yet another CRUD. This time in Rust.

crust ____ ____ _ ____ _____ / _\/ __\/ \ /\/ ___\/__ __\ | / | \/|| | ||| \ / \ | \__| /| \_/|\___ | | | \____/\_/\_\\___

Leandro Proença 5 Dec 20, 2023
CRUD system of book-management with ORM and JWT for educational purposes.

Book management English | 中文 Required Rust MySQL 5.7 Usage Execute init.sql to create tables. Set environment variable DATABASE_URL and JWT_SECRET in

null 32 Dec 28, 2022
The most efficient, scalable, and fast production-ready serverless REST API backend which provides CRUD operations for a MongoDB collection

Optimal CRUD Mongo Goals of This Project This is meant to be the most efficient, scalable, and fast production-ready serverless REST API backend which

Evaluates2 1 Feb 22, 2022