Skip to content

Commit

Permalink
Revamp SeaORM Tutorials (Issue #8) (#9)
Browse files Browse the repository at this point in the history
* Revamped outline

* Rewrite introduction

* Remove old tutorials

* Draft ch01-00

* Draft ch01-01

* Edit SQLite (in file) example URL

* Add bakery-backend source code

* Add `sea-orm-migration` dependency

* Create migrator module

* Create migrations

* Use Migrator to define the database schema

* Draft ch01-02

* Draft ch01-03

* Draft ch01-04

* Insert and update

* Find (single entity)

* Delete

* Draft ch01-06

* Draft ch01-07

* Remove PostgreSQL prompt symbol guide

* Add reminder of executing sea-orm-cli at the project root

* Specify file path of Cargo.toml

* intro: "the most" -> "a"

* Remove legacy example source files

* Draft ch01-08

* Add SeaQuery usage source code

* Add Rocket integration example source code

* Update SUMMARY

* Section rename: "Fetch from Database" -> "Connect to Database"

* Draft ch02-00

* Remove # in SUMMARY.md

* Add `/reset` endpoint in Rocket integration example source code

* Draft ch02-01

* Add templates to provide a minimal frontend

* Remove non-existent handler in ch02-01

* Draft ch02-02

* Add section for simple frontend using templates in plan

* Draft ch02-03

* Add mounting new endpoint handler in ch02-02

* Draft ch02-04

* Draft ch02-05

* Merge Billy's changes

* Update ch01-00-simple-crud-getting-started.md (#10)

Missing features "attributes" for async-std. Thank you!

* Remove old tutorial section ch01-00-simple-crud-getting-started.md

* Update GitHub workflows for building the examples

* Update README.md

* Prepare for early release (postponing the release of chapter 3)

Co-authored-by: Nicolas Carranza <[email protected]>
  • Loading branch information
shpun817 and nicarran authored Jun 27, 2022
1 parent 771705d commit e53392f
Show file tree
Hide file tree
Showing 105 changed files with 3,391 additions and 3,949 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
toolchain: stable

# Try to build all examples
- name: Build simple-crud example
run: cargo build --manifest-path simple-crud/Cargo.toml
- name: Build todo-app example
run: cargo build --manifest-path todo-app/Cargo.toml
- name: Build bakery-backend example
run: cargo build --manifest-path bakery-backend/Cargo.toml
- name: Build rocket-example
run: cargo build --manifest-path rocket-example/Cargo.toml

# Try to build mdbooks
- name: Install mdbook
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[workspace]
members = ["bakery-backend", "rocket-example"]
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# SeaORM Tutorials

This repository contains step-by-step tutorials on how to use SeaORM to do CRUD operations from simple ones to very complex online applications in Rust Language.
This repository contains step-by-step tutorials on how to use SeaORM to do CRUD operations on databases in the Rust Language.

The tutorial is based on a software system for managing fruits in a fruit market.
The tutorial is based on a software system for managing a simple database to store information of bakeries.

The tutorials are
The tutorials contain the following chapters:

1. [**Simple CRUD operations**](https://www.sea-ql.org/sea-orm-tutorial/ch01-00-simple-crud-getting-started.html) - This tutorials explains how to use SeaORM to do basic tasks like create a table in a database, insert a row into the table, update a column, delete operations and logging the results to the console. The database used is MySQL
2. [**TODO Application**](https://www.sea-ql.org/sea-orm-tutorial/ch02-00-todo-app-getting-started.html) - This tutorial shows how to use SeaORM, SQLite and PostgreSQL to create a realtime sync TODO application where a user can buy fruits from the mango market.
1. [**Bakery Backend**](https://www.sea-ql.org/sea-orm-tutorial/ch01-00-build-backend-getting-started.html) - This chapter covers the basics of using SeaORM to interact with the database (a MySQL database is used for illustration). On top of this backend you can build any interface you need.
2. [**Rocket Integration**](https://www.sea-ql.org/sea-orm-tutorial/ch02-00-integration-with-rocket.html) - This chapter explains how to integrate the SeaORM backend into the Rocket framework to create a web application that provides a web API or even a simple frontend.

[![Discord](https://img.shields.io/discord/873880840487206962?label=Discord)](https://discord.com/invite/uCPdDXzbdv)

For additional help on **SeaORM** specific questions, join the support Discord chat.

## Running the tutorials

To run the tutorial code, switch to the directory of the turorial and run cargo
To run the tutorial code, switch to the directory of the tutorial and run cargo

```sh
# Switch to tutorial directory
Expand Down
1 change: 1 addition & 0 deletions bakery-backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
11 changes: 11 additions & 0 deletions bakery-backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "bakery-backend"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = "0.3.21"
sea-orm = { version = "0.8.0", features = [ "sqlx-mysql", "runtime-async-std-native-tls", "macros", "mock" ] }
sea-orm-migration = "0.8.3"
33 changes: 33 additions & 0 deletions bakery-backend/src/entities/baker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.8.0
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "baker")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
pub contact_details: Option<Json>,
pub bakery_id: i32,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::bakery::Entity",
from = "Column::BakeryId",
to = "super::bakery::Column::Id",
on_update = "NoAction",
on_delete = "NoAction"
)]
Bakery,
}

impl Related<super::bakery::Entity> for Entity {
fn to() -> RelationDef {
Relation::Bakery.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
26 changes: 26 additions & 0 deletions bakery-backend/src/entities/bakery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.8.0
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "bakery")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
pub profit_margin: f64,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::baker::Entity")]
Baker,
}

impl Related<super::baker::Entity> for Entity {
fn to() -> RelationDef {
Relation::Baker.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
6 changes: 6 additions & 0 deletions bakery-backend/src/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.8.0
pub mod prelude;

pub mod baker;
pub mod bakery;
4 changes: 4 additions & 0 deletions bakery-backend/src/entities/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.8.0
pub use super::baker::Entity as Baker;
pub use super::bakery::Entity as Bakery;
Loading

0 comments on commit e53392f

Please sign in to comment.