Skip to content

Commit 929eeb9

Browse files
committed
[Blog] Edit
1 parent a3936ec commit 929eeb9

File tree

2 files changed

+57
-57
lines changed

2 files changed

+57
-57
lines changed

Blog/blog/2025-10-20-sea-orm-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub enum Relation {
354354
}
355355
```
356356

357-
This aspect is not different from 1.0. A `Related` impl will not be generated. The relation can be used in joins, but currently not supported by the loader (we do plan to support it soon).
357+
This aspect is not so different from 1.0. A `Related` impl will not be generated, but the relation can still be used in loader.
358358

359359
### Composite foreign key
360360

Blog/blog/2025-10-30-sea-orm-2.0.md

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SeaORM used to adopt a schema‑first approach: meaning you design database tabl
2525

2626
Entity‑first flips the flow: you hand-write the entity files, and let SeaORM generates the tables and foreign keys for you.
2727

28-
All you have to do is to add the following to your `main.rs` right after creating the database connection:
28+
All you have to do is to add the following to your [`main.rs`](https://github.com/SeaQL/sea-orm/blob/master/examples/quickstart/src/main.rs) right after creating the database connection:
2929

3030
```rust
3131
let db = &Database::connect(db_url).await?;
@@ -37,7 +37,9 @@ This requires two feature flags `schema-sync` and `entity-registry`, and we're g
3737

3838
## Unfolding
3939

40-
The above function `get_schema_registry` desugars into the following:
40+
### Entity Registry
41+
42+
The above function `get_schema_registry` unfolds into the following:
4143

4244
```rust
4345
db.get_schema_builder()
@@ -53,7 +55,7 @@ You might be wondering: how can SeaORM recognize my entities when, at compile ti
5355

5456
Rest assured, there's no source‑file scanning or other hacks involved - this is powered by the brilliant [`inventory`](https://docs.rs/inventory/latest/inventory/) crate. The `inventory` crate works by registering items (called plugins) into linker-collected sections.
5557

56-
At compile-time, each `Entity` module registers itself to the global `inventory` along with their module paths and some metadata. On runtime, SeaORM then filters the Entities you requested and construct a `SchemaBuilder`.
58+
At compile-time, each `Entity` module registers itself to the global `inventory` along with their module paths and some metadata. On runtime, SeaORM then filters the Entities you requested and construct a [`SchemaBuilder`](https://docs.rs/sea-orm/2.0.0-rc.15/sea_orm/schema/struct.SchemaBuilder.html).
5759

5860
The `EntityRegistry` is completely optional and just adds extra convenience, it's perfectly fine for you to `register` Entities manually like above.
5961

@@ -73,13 +75,14 @@ Let's walk through the different scenarios:
7375

7476
Let's say you added a new Entity under `mod.rs`
7577

76-
```rust
78+
```rust title="entity/mod.rs"
7779
//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.14
7880

7981
pub mod prelude;
8082

8183
pub mod post;
8284
pub mod upvote; // ⬅ new entity module
85+
..
8386
```
8487

8588
The next time you `cargo run`, you'll see the following:
@@ -92,22 +95,21 @@ This will create the table along with any foreign keys.
9295

9396
### Adding Columns
9497

95-
```rust
96-
mod profile {
97-
use sea_orm::entity::prelude::*;
98-
99-
#[sea_orm::model]
100-
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
101-
#[sea_orm(table_name = "profile")]
102-
pub struct Model {
103-
#[sea_orm(primary_key)]
104-
pub id: i32,
105-
pub picture: String,
106-
pub date_of_birth: Option<DateTimeUtc>, // ⬅ new column
107-
}
108-
109-
impl ActiveModelBehavior for ActiveModel {}
98+
```rust title="entity/profile.rs"
99+
use sea_orm::entity::prelude::*;
100+
101+
#[sea_orm::model]
102+
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
103+
#[sea_orm(table_name = "profile")]
104+
pub struct Model {
105+
#[sea_orm(primary_key)]
106+
pub id: i32,
107+
pub picture: String,
108+
pub date_of_birth: Option<DateTimeUtc>, // ⬅ new column
109+
..
110110
}
111+
112+
impl ActiveModelBehavior for ActiveModel {}
111113
```
112114

113115
The next time you `cargo run`, you'll see the following:
@@ -161,27 +163,27 @@ Nice, isn't it?
161163

162164
### Add Foreign Key
163165

164-
Let's say we create a new table with a foreign key:
166+
Let's create a new table with a foreign key:
165167

166-
```rust
167-
mod upvote {
168-
use sea_orm::entity::prelude::*;
169-
170-
#[sea_orm::model]
171-
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
172-
#[sea_orm(table_name = "upvote")]
173-
pub struct Model {
174-
#[sea_orm(primary_key, auto_increment = false)]
175-
pub post_id: i32,
176-
#[sea_orm(belongs_to, from = "post_id", to = "id")]
177-
pub post: HasOne<super::post::Entity>,
178-
..
179-
}
180-
181-
impl ActiveModelBehavior for ActiveModel {}
168+
```rust title="entity/upvote.rs"
169+
use sea_orm::entity::prelude::*;
170+
171+
#[sea_orm::model]
172+
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
173+
#[sea_orm(table_name = "upvote")]
174+
pub struct Model {
175+
#[sea_orm(primary_key, auto_increment = false)]
176+
pub post_id: i32,
177+
#[sea_orm(belongs_to, from = "post_id", to = "id")]
178+
pub post: HasOne<super::post::Entity>,
179+
..
182180
}
181+
182+
impl ActiveModelBehavior for ActiveModel {}
183183
```
184184

185+
The next time you `cargo run`, you'll see the following:
186+
185187
```sh
186188
CREATE TABLE "upvote" (
187189
"post_id" integer NOT NULL PRIMARY KEY,
@@ -196,22 +198,20 @@ If however, the `post` relation is added after the table has been created, then
196198

197199
Now, let's say we've forgotten to add a unique constraint on user name:
198200

199-
```rust
200-
mod user {
201-
use sea_orm::entity::prelude::*;
202-
203-
#[sea_orm::model]
204-
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
205-
#[sea_orm(table_name = "user")]
206-
pub struct Model {
207-
#[sea_orm(primary_key)]
208-
pub id: i32,
209-
#[sea_orm(unique)] // ⬅ add unique key
210-
pub name: String,
211-
#[sea_orm(unique)]
212-
pub email: String,
213-
..
214-
}
201+
```rust title="entity/user.rs"
202+
use sea_orm::entity::prelude::*;
203+
204+
#[sea_orm::model]
205+
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
206+
#[sea_orm(table_name = "user")]
207+
pub struct Model {
208+
#[sea_orm(primary_key)]
209+
pub id: i32,
210+
#[sea_orm(unique)] // ⬅ add unique key
211+
pub name: String,
212+
#[sea_orm(unique)]
213+
pub email: String,
214+
..
215215
}
216216
```
217217

@@ -221,7 +221,7 @@ The next time you `cargo run`, you'll see the following:
221221
CREATE UNIQUE INDEX "idx-user-name" ON "user" ("name")
222222
```
223223

224-
As mentioned in the previous blog post, you'll also get a shorthand method generated on the Entity for free:
224+
As mentioned in the previous blog post, you'll also get a shorthand method generated on the Entity:
225225

226226
```rust
227227
user::Entity::find_by_name("Bob")..
@@ -253,11 +253,11 @@ DROP INDEX "idx-user-name"
253253

254254
Note that in general schema sync would not attempt to do any destructive actions, so meaning no `DROP` on tables, columns and foreign keys. Dropping index is an exception here.
255255

256-
Every time the application starts, a full schema discovery is performed. It's not recommended to enable this in production, and so this is gated behind a feature flag `schema-sync` that can be turned off based on build profile.
256+
Every time the application starts, a full schema discovery is performed. This may not be desirable in production, so `sync` is gated behind a feature flag `schema-sync` that can be turned off based on build profile.
257257

258258
## 🧭 Instant GraphQL API
259259

260-
With [Seaography](https://github.com/SeaQL/seaography), the Entities you wrote can instantly be exposed as a GraphQL schema, with full CRUD, filtering and pagination. The GraphQL data loader is actually more powerful, as it allows nesting relations with arbitrary complexity.
260+
With [Seaography](https://github.com/SeaQL/seaography), the Entities you wrote can *instantly* be exposed as a GraphQL schema, with full CRUD, filtering and pagination. No extra macros, no Entity re-generation is needed!
261261

262262
With SeaORM and Seaography, you can prototype quickly and stay in the flow. And because Seaography is highly customizable, you can gradually shift resolver logic into your own implementation as the application evolves, and layer access control on top before the project goes to production.
263263

@@ -296,7 +296,7 @@ type User {
296296
}
297297
```
298298

299-
## 🖥️ SeaORM Pro: Professional Admin Panel
299+
## 🖥️ SeaORM Pro: Admin Panel
300300

301301
<img src="/blog/img/sea-orm-pro-light.png#light" />
302302
<img src="/blog/img/sea-orm-pro-dark.png#dark" />

0 commit comments

Comments
 (0)