Giter VIP home page Giter VIP logo

actix_sqlx_mysql_user_crud's Introduction

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 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

The following message should be printed to the terminal:

=== SQLX User CRUD ===
Using configuration file from config.json
Connected to database: mysql://sqlx_user_crud:rust_is_the_future@localhost/actix_user_crud
Listening on: 127.0.0.1:8000

actix_sqlx_mysql_user_crud's People

Contributors

jamesjmeyer210 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.