SeaQL / sea-orm-tutorial

ebook for SeaORM tutorial
http://www.sea-ql.org/sea-orm-tutorial/
Apache License 2.0
37 stars 12 forks source link

Plans to Revamp SeaORM Tutorial #8

Open billy1624 opened 2 years ago

billy1624 commented 2 years ago

We would like to rewrite SeaORM tutorial and align with SeaORM 0.8.0 and beyond.

We're going to have two types of tutorial:

  1. The Basics of SeaORM: covers all essentials of SeaORM, including db setup and connection, db migration, generating entity files, CRUD operations, relational selects and mock testing
  2. Integrating with SeaORM: showcase how to integrate SeaORM with other framework, including but not limited to Rocket, Actix, Async GraphQL

To make the tutorial more realistic and interesting, we could have theme across our tutorial.

The Basics of SeaORM

Table of Content

Integrating with SeaORM

This would be split into multiple tutorials that depend on prior knowledge of "The Basics of SeaORM".

Frameworks to be included


Your comments, suggestions and feedbacks are appreciated! Please leave a comment below and let us know your thoughts :)

CC @tyt2y3

nahuakang commented 2 years ago

I'd be happy to help work out the new tutorials as much as time allows 🥳

One general question:

Two specific questions:

From my part, I've not worked with gRPC or GraphQL yet. Could use support there.

billy1624 commented 2 years ago

Hey @nahuakang,

Let me know your thoughts :)

billy1624 commented 2 years ago

Hey @nahuakang, @shpun817 and I will take on this task :)

shpun817 commented 2 years ago

Proposed outline of the revamped tutorial:

SeaORM Tutorials

Introduction

Chapter 1 - Building a Backend with SeaORM

Chapter 2 - Integration with Rocket

Chapter 3 - Integration with GraphQL

billy1624 commented 2 years ago

We still have chapter 3 and more

billy1624 commented 2 years ago

More tutorials are welcomed! e.g. advanced topics in SeaORM, step-by-step integration example for SeaORM with frameworks such as gRPC, etc.

nahuakang commented 2 years ago

The new tutorial looks amazing 🥇 (sorry I didn't help out at all). I'll read it as soon as I can and give feedback from the view of a new user :)

billy1624 commented 2 years ago

Hey @nahuakang, no worries! Please let us know your thoughts on the new SeaORM tutorials :)

nahuakang commented 2 years ago

I left some edits on Chapter 1: https://github.com/SeaQL/sea-orm-tutorial/pull/18. Overall this chapter gave a very smooth introduction to how to link up sea-orm with a cargo project and is a significant upgrade for me.

https://www.sea-ql.org/sea-orm-tutorial/ch01-08-sql-with-sea-query.html is perhaps the most confusing to me. Some lines, such as Invoke values_panic() for each row, seem confusing to me and I struggle to see the benefits of using SeaQuery over raw SQL or SeaORM. Maybe we could add some paragraphs on why and when SeaQuery will shine?

Edit: I think sea-query README emphasizes the advantage of SeaQuery very well so maybe a few sentences copied from the README would work already 😄

billy1624 commented 2 years ago

I think using SeaQuery to construct query statement while executing it on SeaORM gives you flexibility over the query building while ease the difficulty of managing the connection and mapping query result into struct.

timuchen commented 3 months ago

Hello! I think you should pay attention to how Relational Query works.

https://www.sea-ql.org/sea-orm-tutorial/ch03-02-query.html

// src/schema.rs

+ #[ComplexObject]
+ impl bakery::Model {
+   async fn chefs(&self, ctx: &Context<'_>) -> Result<Vec<chef::Model>, DbErr> {
+       let db = ctx.data::<DatabaseConnection>().unwrap();
+
+       self.find_related(Chef).all(db).await
+   }
+ }

// src/entities/bakery.rs

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, SimpleObject)]
+ #[graphql(complex, name = "Bakery")]
#[sea_orm(table_name = "bakery")]
pub struct Model {

I get: Inherent impl cannot be defined for a type outside its containing crate [E0116]

Obviously, it is necessary to describe a different approach, since we want to move the GraphQl logic to another crate.

When we add a ComplexObject directly to an Entity, we lose context.

billy1624 commented 2 months ago

Interesting. If you look at the full source code (https://www.sea-ql.org/sea-orm-tutorial/ch03-00-integration-with-graphql.html) The impl is actually on reside in the same crate where the entity is defined.