Skip to content

Commit 7d77384

Browse files
committed
[SeaORM] edit
1 parent 40ed28a commit 7d77384

30 files changed

+567
-539
lines changed

β€ŽSeaORM/docs/01-index.mdβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676

7777
6.4 [Complex Relations](06-relation/04-complex-relations.md)
7878

79-
6.5 [Custom Join Condition](06-relation/06-custom-join-condition.md)
79+
6.5 [Model Loader](06-relation/06-model-loader.md)
8080

81-
6.6 [Data Loader](06-relation/07-data-loader.md)
81+
6.6 [Entity Loader](06-relation/07-entity-loader.md)
8282

8383
6.7 [Bakery Schema](06-relation/08-bakery-schema.md)
8484

@@ -116,6 +116,8 @@
116116

117117
8.9 [Error Handling](08-advanced-query/09-error-handling.md)
118118

119+
8.10 [Custom Join Condition](08-advanced-query/10-custom-join-condition.md)
120+
119121
9. Schema Statement
120122

121123
9.1 [Create Table](09-schema-statement/01-create-table.md)

β€ŽSeaORM/docs/01-introduction/03-sea-orm.mdβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Each table corresponds to an [`Entity`](04-generate-entity/02-entity-format.md#e
66

77
The `Entity` trait provides an API for you to inspect its properties ([`Column`](04-generate-entity/02-entity-format.md#column), [`Relation`](04-generate-entity/02-entity-format.md#relation) and [`PrimaryKey`](04-generate-entity/02-entity-format.md#primary-key)) at runtime.
88

9-
Each table has multiple columns, which are referred to as `attribute`.
9+
Each table has multiple columns, which are referred to as field.
1010

11-
These attributes and their values are grouped in a Rust struct (a [`Model`](12-internal-design/05-expanded-entity-format.md#model)) so that you can manipulate them.
11+
These fields and their values are grouped in a Rust struct (a [`Model`](12-internal-design/05-expanded-entity-format.md#model)) so that you can manipulate them.
1212

13-
However, `Model` is for read operations only. To perform insert, update, or delete, you need to use [`ActiveModel`](12-internal-design/05-expanded-entity-format.md#active-model) which attaches meta-data on each attribute.
13+
However, `Model` is for read operations only. To perform insert, update, or delete, you need to use [`ActiveModel`](12-internal-design/05-expanded-entity-format.md#active-model) which attaches a state on each field.
1414

15-
Finally, there is no singleton (global context) in SeaORM. Application code is responsible for managing the ownership of the `DatabaseConnection`. We do provide integration examples for web frameworks including [Rocket](https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_example), [Actix](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example), [axum](https://github.com/SeaQL/sea-orm/tree/master/examples/axum_example) and [poem](https://github.com/SeaQL/sea-orm/tree/master/examples/poem_example) to help you get started quickly.
15+
Finally, there is no singleton (global context) in SeaORM. Application code is responsible for managing the ownership of the `DatabaseConnection`. We do provide integration examples for web frameworks including [Actix](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example), [axum](https://github.com/SeaQL/sea-orm/tree/master/examples/axum_example) and [poem](https://github.com/SeaQL/sea-orm/tree/master/examples/poem_example), [Loco](https://github.com/SeaQL/sea-orm/tree/master/examples/loco_example) to help you get started quickly.

β€ŽSeaORM/docs/01-introduction/04-tutorial.mdβ€Ž

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ If you prefer a step-by-step tutorial on how to use SeaORM, you can check out ou
44

55
You can also check out [SeaORM Cookbook](https://www.sea-ql.org/sea-orm-cookbook/) for some frequently asked questions and recommended practices of using SeaORM.
66

7-
If you are so eager and want something grab-and-go, SeaQL maintains a set of official examples contributed by the community (we welcome more!):
7+
If you are so eager and want something grab-and-go, SeaQL maintains a set of official examples (we welcome more!):
88

9-
+ [Actix Example](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example)
9+
Integration examples:
10+
11+
+ [Actix v4 Example](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example)
1012
+ [Axum Example](https://github.com/SeaQL/sea-orm/tree/master/examples/axum_example)
1113
+ [GraphQL Example](https://github.com/SeaQL/sea-orm/tree/master/examples/graphql_example)
1214
+ [jsonrpsee Example](https://github.com/SeaQL/sea-orm/tree/master/examples/jsonrpsee_example)
13-
+ [Loco Example](https://github.com/SeaQL/sea-orm/tree/master/examples/loco_example)
14-
+ [Loco REST Starter Example](https://github.com/SeaQL/sea-orm/tree/master/examples/loco_starter)
15+
+ [Loco TODO Example](https://github.com/SeaQL/sea-orm/tree/master/examples/loco_example) / [Loco REST Starter](https://github.com/SeaQL/sea-orm/tree/master/examples/loco_starter)
1516
+ [Poem Example](https://github.com/SeaQL/sea-orm/tree/master/examples/poem_example)
16-
+ [Rocket Example](https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_example)
17+
+ [Rocket Example](https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_example) / [Rocket OpenAPI Example](https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_okapi_example)
1718
+ [Salvo Example](https://github.com/SeaQL/sea-orm/tree/master/examples/salvo_example)
1819
+ [Tonic Example](https://github.com/SeaQL/sea-orm/tree/master/examples/tonic_example)
19-
+ [Seaography Example](https://github.com/SeaQL/sea-orm/tree/master/examples/seaography_example)
20+
+ [Seaography Example (Bakery)](https://github.com/SeaQL/sea-orm/tree/master/examples/seaography_example) / [Seaography Example (Sakila)](https://github.com/SeaQL/seaography/tree/main/examples/sqlite)
21+
22+
If you want a simple, clean example that fits in a single file that demonstrates the best of SeaORM, you can try:
23+
+ [Quickstart](https://github.com/SeaQL/sea-orm/blob/master/examples/quickstart/src/main.rs)

β€ŽSeaORM/docs/02-install-and-config/01-database-and-async-runtime.mdβ€Ž

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,33 @@ The installation and configuration of MSSQL driver can be found [here](https://w
3030

3131
## ASYNC_RUNTIME
3232

33-
You have to choose one from:
34-
35-
`runtime-async-std-native-tls`, `runtime-tokio-native-tls`, `runtime-async-std-rustls`, `runtime-tokio-rustls`
33+
You have to choose one from: `runtime-tokio-native-tls`, `runtime-tokio-rustls`
3634

3735
Basically, they are in the form of `runtime-ASYNC_RUNTIME-TLS_LIB`:
3836

39-
+ `ASYNC_RUNTIME` can be [`async-std`](https://crates.io/crates/async-std) or [`tokio`](https://crates.io/crates/tokio)
37+
+ `ASYNC_RUNTIME` can be [`tokio`](https://crates.io/crates/tokio)
38+
+ `async-std` has been deprecated
4039
+ `TLS_LIB` can either be [`native-tls`](https://crates.io/crates/native-tls) or [`rustls`](https://crates.io/crates/rustls)
41-
42-
1. Choose the ASYNC_RUNTIME corresponding to your Rust web framework:
43-
44-
| ASYNC_RUNTIME | Web Framework |
45-
| :-----------: | :------------: |
46-
| `async-std` | [`Tide`](https://docs.rs/tide) |
47-
| `tokio` | [`Axum`](https://docs.rs/axum), [`Actix`](https://actix.rs/), [`Poem`](https://docs.rs/poem), [`Rocket`](https://rocket.rs/) |
48-
49-
2. `native-tls` uses the platform's native security facilities, while `rustls` is an (almost) pure Rust implementation.
40+
+ `native-tls` uses the platform's native security facilities, while `rustls` is an (almost) pure Rust implementation.
5041

5142
## Extra features
5243

5344
+ `debug-print` - print every SQL statement to logger
5445
+ `mock` - mock interface for unit testing
55-
+ `macros` - procedural macros for your convenience
46+
+ `macros` - procedural macros, e.g. DeriveEntityModel
47+
+ `rbac` - role-based access control
48+
+ `seaography` - enable GraphQL support
49+
+ `schema-sync` - enable sync features in SchemaBuilder
50+
<br/>
5651
+ `with-chrono` - support [`chrono`](https://crates.io/crates/chrono) types
5752
+ `with-time` - support [`time`](https://crates.io/crates/time) types
5853
+ `with-json` - support [`serde-json`](https://crates.io/crates/serde-json) types
5954
+ `with-rust_decimal` - support [`rust_decimal`](https://crates.io/crates/rust_decimal) types
6055
+ `with-bigdecimal` - support [`bigdecimal`](https://crates.io/crates/bigdecimal) types
6156
+ `with-uuid` - support [`uuid`](https://crates.io/crates/uuid) types
62-
+ `postgres-array` - support array types in Postgres (automatically enabled when `sqlx-postgres` feature is turned on)
63-
+ `sea-orm-internal` - opt-in unstable internal APIs (for accessing re-export SQLx types)
57+
+ `with-ipnetwork` - support Postgres [`ipnetwork`](https://crates.io/crates/ipnetwork)
58+
+ `postgres-vector` - support Postgres [`pgvector`](https://crates.io/crates/pgvector)
59+
+ `postgres-array` - support array types in Postgres, enabled by default
60+
<br/>
61+
+ `sqlite-use-returning-for-3_35` - use returning for SQLite, enabled by default
62+
+ `mariadb-use-returning` - use returning for MariaDB

β€ŽSeaORM/docs/02-install-and-config/02-connection.mdβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ opt.max_connections(100)
7272
.acquire_timeout(Duration::from_secs(8))
7373
.idle_timeout(Duration::from_secs(8))
7474
.max_lifetime(Duration::from_secs(8))
75-
.sqlx_logging(true)
75+
.sqlx_logging(false) // disable SQLx logging
7676
.sqlx_logging_level(log::LevelFilter::Info)
77-
.set_schema_search_path("my_schema"); // Setting default PostgreSQL schema
77+
.set_schema_search_path("my_schema"); // set default Postgres schema
7878

7979
let db = Database::connect(opt).await?;
8080
```
8181

82-
## Checking Connection is Valid
82+
## Check if connection is valid
8383

8484
Checks if a connection to the database is still valid.
8585

8686
```rust
87-
|db: DatabaseConnection| {
87+
async fn check(db: DatabaseConnection) {
8888
assert!(db.ping().await.is_ok());
8989
db.clone().close().await;
9090
assert!(matches!(db.ping().await, Err(DbErr::ConnectionAcquire)));

β€ŽSeaORM/docs/02-install-and-config/03-debug-log.mdβ€Ž

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Debug Log
22

3+
## Statement Logging
4+
35
SeaORM logs debug messages via the [`tracing`](https://crates.io/crates/tracing) crate.
46

57
You can enable SeaORM's logging with the `debug-print` feature flag:
@@ -23,17 +25,25 @@ pub async fn main() {
2325
}
2426
```
2527

26-
SeaORM's debug print injects parameters into the SQL string, which makes it easier to read. Instead of seeing `SELECT "chef"."name" FROM "chef" WHERE "chef"."id" = $1`, you will see `SELECT "chef"."name" FROM "chef" WHERE "chef"."id" = 100`.
28+
SeaORM's debug print injects parameters into the SQL string, which makes it easier to read. Instead of seeing:
29+
30+
```sql
31+
SELECT "cake"."name" FROM "cake" WHERE "cake"."id" = $1
32+
```
33+
34+
you will see:
35+
36+
```sql
37+
SELECT "cake"."name" FROM "cake" WHERE "cake"."id" = 101
38+
```
2739

2840
## SQLx Logging
2941

3042
SQLx also logs by default. If you turned on SeaORM's `debug-print`, you can disable SQLx's log by passing [`ConnectOptions`](https://docs.rs/sea-orm/*/sea_orm/struct.ConnectOptions.html) to `connect()`.
3143

3244
```rust
3345
let mut opt = ConnectOptions::new("protocol://username:password@host/database".to_owned());
34-
opt
35-
.sqlx_logging(false) // Disable SQLx log
36-
.sqlx_logging_level(log::LevelFilter::Info); // Or set SQLx log level
46+
opt.sqlx_logging(false); // disable SQLx logging
3747

3848
let db = Database::connect(opt).await?;
3949
```

β€ŽSeaORM/docs/03-migration/01-setting-up-migration.mdβ€Ž

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,22 @@ Note that if you setup the migration directory directly within a Git repository,
7575

7676
## Workspace Structure
7777

78-
It is recommended to structure your cargo workspace as follows to share SeaORM entities between the app crate and the migration crate. Checkout the [integration examples](https://github.com/SeaQL/sea-orm/tree/master/examples) for demonstration.
78+
It is recommended to structure your project as a cargo workspace to separate the app crate and the migration crate. Checkout the [integration examples](https://github.com/SeaQL/sea-orm/tree/master/examples) for demonstration.
7979

8080
### Migration Crate
8181

8282
Import the [`sea-orm-migration`](https://crates.io/crates/sea-orm-migration) and [`async-std`](https://crates.io/crates/async-std) crate.
8383

8484
```toml title="migration/Cargo.toml"
8585
[dependencies]
86-
async-std = { version = "1", features = ["attributes", "tokio1"] }
86+
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
8787

8888
[dependencies.sea-orm-migration]
89-
version = "2.0.0-rc"
89+
version = "~2.0.0-rc" # sea-orm-migration version
9090
features = [
91-
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
92-
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
93-
# e.g.
94-
# "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
95-
# "sqlx-postgres", # `DATABASE_DRIVER` feature
91+
# Enable following runtime and db backend features if you want to run migration via CLI
92+
# "runtime-tokio-native-tls",
93+
# "sqlx-postgres",
9694
]
9795
```
9896

@@ -118,53 +116,20 @@ impl MigrationTrait for Migration {
118116
}
119117
```
120118

121-
### Entity Crate
122-
123-
Create an entity crate in your root workspace.
124-
125-
<details>
126-
<summary>You don't have SeaORM entities defined?</summary>
127-
128-
You can create an entity crate without any entity files. Then, write the migration and run it to create tables in the database. Finally, [generate SeaORM entities](04-generate-entity/01-sea-orm-cli.md) with `sea-orm-cli` and output the entity files to `entity/src/entities` folder.
129-
130-
After generating the entity files, you can re-export the generated entities by adding following lines in `entity/src/lib.rs`:
131-
132-
```rust
133-
mod entities;
134-
pub use entities::*;
135-
```
136-
</details>
137-
138-
```
139-
entity
140-
β”œβ”€β”€ Cargo.toml # Include SeaORM dependency
141-
└── src
142-
β”œβ”€β”€ lib.rs # Re-export SeaORM and entities
143-
└── post.rs # Define the `post` entity
144-
```
145-
146-
Specify SeaORM dependency.
147-
148-
```toml title="entity/Cargo.toml"
149-
[dependencies]
150-
sea-orm = { version = "2.0.0-rc" }
151-
```
152-
153119
### App Crate
154120

155-
This is where the application logic goes.
121+
This is where the application logic belongs.
156122

157123
Create a workspace that contains app, entity and migration crates and import the entity crate into the app crate.
158124

159125
If we want to bundle the migration utility as part of your app, you'd also want to import the migration crate.
160126

161127
```toml title="./Cargo.toml"
162128
[workspace]
163-
members = [".", "entity", "migration"]
129+
members = [".", "migration"]
164130

165131
[dependencies]
166-
entity = { path = "entity" }
167-
migration = { path = "migration" } # depends on your needs
132+
migration = { path = "migration" }
168133

169134
[dependencies]
170135
sea-orm = { version = "2.0.0-rc", features = [..] }

0 commit comments

Comments
Β (0)