Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a62f936
Revamped outline
shpun817 May 31, 2022
b37e29b
Rewrite introduction
shpun817 May 31, 2022
0030125
Remove old tutorials
shpun817 May 31, 2022
d7aed2d
Draft ch01-00
shpun817 May 31, 2022
1601c5a
Draft ch01-01
shpun817 Jun 2, 2022
8da1947
Edit SQLite (in file) example URL
shpun817 Jun 2, 2022
8f80893
Add bakery-backend source code
shpun817 May 31, 2022
f460284
Add `sea-orm-migration` dependency
shpun817 Jun 2, 2022
a1c4b7f
Create migrator module
shpun817 Jun 2, 2022
2e9abbc
Create migrations
shpun817 Jun 2, 2022
e7bccb5
Use Migrator to define the database schema
shpun817 Jun 2, 2022
e7b8dcf
Draft ch01-02
shpun817 Jun 2, 2022
6d62e73
Draft ch01-03
shpun817 Jun 7, 2022
1591908
Draft ch01-04
shpun817 Jun 7, 2022
074fc35
Insert and update
shpun817 Jun 7, 2022
463d921
Find (single entity)
shpun817 Jun 9, 2022
ec2cc8c
Delete
shpun817 Jun 9, 2022
dddb2c8
Draft ch01-06
shpun817 Jun 9, 2022
4aa363d
Draft ch01-07
shpun817 Jun 9, 2022
206679a
Remove PostgreSQL prompt symbol guide
shpun817 Jun 9, 2022
322fc91
Add reminder of executing sea-orm-cli at the project root
shpun817 Jun 9, 2022
16bb659
Specify file path of Cargo.toml
shpun817 Jun 9, 2022
00c194a
intro: "the most" -> "a"
shpun817 Jun 12, 2022
c8227cb
Remove legacy example source files
shpun817 Jun 14, 2022
2617f6e
Draft ch01-08
shpun817 Jun 14, 2022
c01ad2e
Add SeaQuery usage source code
shpun817 Jun 14, 2022
679fc6f
Add Rocket integration example source code
shpun817 Jun 16, 2022
dc4a156
Update SUMMARY
shpun817 Jun 16, 2022
28a805e
Section rename: "Fetch from Database" -> "Connect to Database"
shpun817 Jun 16, 2022
ab45421
Draft ch02-00
shpun817 Jun 16, 2022
c70b256
Remove # in SUMMARY.md
shpun817 Jun 16, 2022
6725296
Add `/reset` endpoint in Rocket integration example source code
shpun817 Jun 16, 2022
a923a0c
Draft ch02-01
shpun817 Jun 16, 2022
eefbbcd
Add templates to provide a minimal frontend
shpun817 Jun 23, 2022
cad9994
Remove non-existent handler in ch02-01
shpun817 Jun 23, 2022
17f48da
Draft ch02-02
shpun817 Jun 23, 2022
f566bb4
Add section for simple frontend using templates in plan
shpun817 Jun 23, 2022
7d5317f
Draft ch02-03
shpun817 Jun 23, 2022
f42fd8c
Add mounting new endpoint handler in ch02-02
shpun817 Jun 23, 2022
3cc3c25
Draft ch02-04
shpun817 Jun 23, 2022
3bf9e44
Draft ch02-05
shpun817 Jun 23, 2022
7735811
Merge Billy's changes
shpun817 Jun 27, 2022
1e3a658
Update ch01-00-simple-crud-getting-started.md (#10)
Jun 7, 2022
dce6160
Remove old tutorial section ch01-00-simple-crud-getting-started.md
shpun817 Jun 27, 2022
26b5389
Update GitHub workflows for building the examples
shpun817 Jun 27, 2022
e2315ad
Update README.md
shpun817 Jun 27, 2022
5abd62b
Prepare for early release (postponing the release of chapter 3)
shpun817 Jun 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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