CRUD example with Rocket, Toql and MySQL

Related tags

Database todo_rotomy
Overview

Todo (Rocket, Toql, MySQL)

This is a little REST server built with Rocket, Toql and MySQL.

The server allows to call CRUD functions on a Todo item.

It demonstrates how easy it is to write REST backends with the Rust programming language.

Get it running

You need a running MySQL server to play around with it.

Then create the database todo_rotomy and insert the Todo table with

CREATE TABLE `Todo` (`id` int(11) NOT NULL AUTO_INCREMENT,`title` varchar(200) NOT NULL, `completed` tinyint(1) DEFAULT 0, PRIMARY KEY (`id`))` 

Now clone this repository

git clone https://github.com/roy-ganz/todo_rotomy.git

Run the server with your database username and password

ROCKET_DATABASES='{todo_rotomy={url=mysql://USER:PASS@localhost:3306/todo_rotomy}}' cargo run

Use the server

Open another terminal and use curl:

Insert a new item

curl localhost:8000/todo -X POST -d '{\"title\":\"Water plants\"}'

Update an item

curl localhost:8000/todo/ID -X PUT -d '{\"completed\":\"true\"}'

List all todo items

curl localhost:8000/todo

Get a single item

curl localhost:8000/todo/ID

Get only completed todos in descending order (example of Toql query)

curl localhost:8000/todo?query=-id,completed+eq+1

Delete an item

curl -X DELETE localhost:8000/todo/ID

Make your own

This project may also serve as a starting point for your own REST server.

However if you plan a big project, it's important to split up your Rust project into separate crates to keep compilation time sane. The #[derive(Toql) adds a lot of code to your structs.

License

Todo-rotomy is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

You might also like...
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

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*

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

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

Example sqlite3 Dynamic Loadable Extension in Rust - vfs and vtab modules - port of vfsstat.c

Example sqlite3 Dynamic Loadable Extension in Rust - vfs and vtab modules The vfs and vtab This is a port of the official ext/misc/vfsstat.c sqlite3 e

Rust and TypeScript example code for finding all members from a collection id.

get-collection-rs Use the Crawler cargo build --release ./target/release/get-collection rpc_node collection_id Example: ./target/release/get-col

A place for the community to upload example Scrypto code

community-scrypto A place for the community to upload example Scrypto code. Please fork from main, work out of a sub-directory of your choosing, and t

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

Matthew Brisebois 3 Dec 3, 2022
Yet another CRUD. This time in Rust.

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

Leandro Proença 5 Dec 20, 2023
🧰 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

launchbadge 7.6k Dec 31, 2022
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

null 45 Nov 16, 2022
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

canalun 7 May 2, 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