Skip to content

Commit

Permalink
Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Aug 2, 2023
1 parent 92fae12 commit e7490c6
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 58 deletions.
2 changes: 1 addition & 1 deletion SeaORM/docs/01-introduction/02-async.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ The first thing to learn is the [`Future`](https://rust-lang.github.io/async-boo

Second, `async` in Rust is [multi-threaded programming](https://rust-lang.github.io/async-book/03_async_await/01_chapter.html) with syntactic sugar. A `Future` may move between threads, so any variables used in async bodies must be able to travel between threads, i.e. [`Send`](https://doc.rust-lang.org/nomicon/send-and-sync.html).

Third, there are multiple async runtimes in Rust. Arguably, [`actix`](https://crates.io/crates/actix), [`async-std`](https://crates.io/crates/async-std) and [`tokio`](https://crates.io/crates/tokio) are the three most widely used. SeaORM's underlying driver, [`SQLx`](https://crates.io/crates/sqlx), supports all three.
Third, there are multiple async runtimes in Rust. [`async-std`](https://crates.io/crates/async-std) and [`tokio`](https://crates.io/crates/tokio) are the two most widely used. SeaORM's underlying driver, [`SQLx`](https://crates.io/crates/sqlx), supports both.

Knowing these concepts is essential to get you up and running in async Rust.
8 changes: 4 additions & 4 deletions SeaORM/docs/03-migration/02-writing-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ Click [here](https://github.com/SeaQL/sea-query#table-create) to take a quick to
You would need [`sea_query::Iden`](https://github.com/SeaQL/sea-query#iden) to define identifiers that will be used in your migration.

```rust
#[derive(Iden)]
#[derive(DeriveIden)]
enum Post {
Table,
Id,
Title,
#[iden = "text"] // Renaming the identifier
#[sea_orm(iden = "text")] // Renaming the identifier
Text,
Category,
}
Expand All @@ -93,12 +93,12 @@ assert_eq!(Post::Text.to_string(), "text");
```rust
use sea_orm::{EnumIter, Iterable};

#[derive(Iden)]
#[derive(DeriveIden)]
enum Post {
Table,
Id,
Title,
#[iden = "text"] // Renaming the identifier
#[sea_orm(iden = "text")] // Renaming the identifier
Text,
Category,
}
Expand Down
3 changes: 1 addition & 2 deletions SeaORM/docs/03-migration/04-seeding-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
pub enum Cake {
Table,
Id,
Expand Down
24 changes: 11 additions & 13 deletions SeaORM/docs/04-generate-entity/02-entity-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ pub struct KeyValue {
```

:::info

Array datatype is supported for PostgreSQL, you can define a vector of any types that are already supported by SeaORM in the model. Keep in mind that you need to enable the `postgres-array` feature and this is a Postgres only feature.

Array datatype is a Postgres-only feature. You can define a vector of types that are already supported by SeaORM.
:::

```rust
Expand Down Expand Up @@ -157,22 +155,22 @@ If you specified a custom `column_type` for an optional attribute, you must also
pub name: Option<String>
```

### Ignore Attribute
### Cast Column Type on Select and Save

If you want to ignore a particular model attribute such that it maps to no database column, you can use the `ignore` annotation.
If you need to select a column as one type but save it into the database as another, you can specify the `select_as` and the `save_as` attributes to perform the casting. A typical use case is selecting a column of type `citext` (case-insensitive text) as `String` in Rust and saving it into the database as `citext`. One should define the model field as below:

```rust
#[sea_orm(ignore)]
pub ignore_me: String
#[sea_orm(select_as = "text", save_as = "citext")]
pub case_insensitive_text: String
```

### Cast Column Type on Select and Save
### Ignore Attribute

If you need to select a column as one type but save it into the database as another, you can specify the `select_as` and the `save_as` attributes to perform the casting. A typical use case is selecting a column of type `citext` (case-insensitive text) as `String` in Rust and saving it into the database as `citext`. One should define the model field as below:
If you want to ignore a particular model attribute such that it maps to no database column, you can use the `ignore` annotation.

```rust
#[sea_orm(select_as = "text", save_as = "citext")]
pub case_insensitive_text: String
#[sea_orm(ignore)]
pub ignore_me: String
```

## Primary Key
Expand All @@ -195,7 +193,7 @@ pub id: i32

### Composite Key

This is usually the case in junction tables, where a two-column tuple is used as the primary key. Simply annotate multiple columns to define a composite primary key. By default, `auto_increment` is `false` for composite key.
This is usually the case in junction tables, where a two-column tuple is used as the primary key. Simply annotate multiple columns to define a composite primary key. `auto_increment` is `false` for composite key.

The max arity of a primary key is 12.

Expand Down Expand Up @@ -233,7 +231,7 @@ Learn more about relations in the [Relation](06-relation/01-one-to-one.md) chapt

## Active Model Behavior

Handlers for different actions on an `ActiveModel`. For example, you can perform custom validation logic or trigger side effects. Inside a transaction, you can even abort an action after it is done, preventing it from saving into the database.
Hooks for different actions on an `ActiveModel`. For example, you can perform custom validation logic or trigger side effects. Inside a transaction, you can even abort an action after it is done, preventing it from saving into the database.

```rust
#[async_trait]
Expand Down
6 changes: 1 addition & 5 deletions SeaORM/docs/06-relation/07-data-loader.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Data Loader

:::tip
If you are building a web API that queries nested relations extensively, consider building a GraphQL server. [Seaography](https://www.sea-ql.org/Seaography/) is a GraphQL framework for building GraphQL resolvers using SeaORM entities. Read "[Getting Started with Seaography](https://www.sea-ql.org/blog/2022-09-27-getting-started-with-seaography/)" to learn more.
:::

The [LoaderTrait](https://docs.rs/sea-orm/*/sea_orm/query/trait.LoaderTrait.html) provides an API to load related entities in batches.

Consider this one to many relation:
Expand Down Expand Up @@ -57,7 +53,7 @@ In an advanced use case, you can apply filters on the related entity:

```rust
let fruits_in_stock: Vec<Vec<fruit::Model>> = cakes.load_many(
fruit::Entity::find().filter(fruit::Column::Stock.gt(0i32))
fruit::Entity::find().filter(fruit::Column::Stock.gt(0i32)),
db
).await?;
```
4 changes: 1 addition & 3 deletions SeaORM/docs/07-write-test/02-mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
You can unit test your application logic using the mock database interface.

:::info

Friendly reminder: you need to enable `mock` feature.

You need to enable the `mock` feature flag in Cargo.toml.
:::

The mock database has no data in it, so you have to define the expected data to be returned when CRUD operations are performed.
Expand Down
2 changes: 1 addition & 1 deletion SeaORM/docs/08-advanced-query/01-custom-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ customer::ActiveModel {
.save(db)
.await?;

// The `notes` field was intentionally leaved out
// The `notes` field was intentionally left out
let customer = Customer::find()
.select_only()
.column(customer::Column::Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ The first thing to learn is the [`Future`](https://rust-lang.github.io/async-boo

Second, `async` in Rust is [multi-threaded programming](https://rust-lang.github.io/async-book/03_async_await/01_chapter.html) with syntactic sugar. A `Future` may move between threads, so any variables used in async bodies must be able to travel between threads, i.e. [`Send`](https://doc.rust-lang.org/nomicon/send-and-sync.html).

Third, there are multiple async runtimes in Rust. Arguably, [`actix`](https://crates.io/crates/actix), [`async-std`](https://crates.io/crates/async-std) and [`tokio`](https://crates.io/crates/tokio) are the three most widely used. SeaORM's underlying driver, [`SQLx`](https://crates.io/crates/sqlx), supports all three.
Third, there are multiple async runtimes in Rust. [`async-std`](https://crates.io/crates/async-std) and [`tokio`](https://crates.io/crates/tokio) are the two most widely used. SeaORM's underlying driver, [`SQLx`](https://crates.io/crates/sqlx), supports both.

Knowing these concepts is essential to get you up and running in async Rust.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ Click [here](https://github.com/SeaQL/sea-query#table-create) to take a quick to
You would need [`sea_query::Iden`](https://github.com/SeaQL/sea-query#iden) to define identifiers that will be used in your migration.

```rust
#[derive(Iden)]
#[derive(DeriveIden)]
enum Post {
Table,
Id,
Title,
#[iden = "text"] // Renaming the identifier
#[sea_orm(iden = "text")] // Renaming the identifier
Text,
Category,
}
Expand All @@ -93,12 +93,12 @@ assert_eq!(Post::Text.to_string(), "text");
```rust
use sea_orm::{EnumIter, Iterable};

#[derive(Iden)]
#[derive(DeriveIden)]
enum Post {
Table,
Id,
Title,
#[iden = "text"] // Renaming the identifier
#[sea_orm(iden = "text")] // Renaming the identifier
Text,
Category,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
pub enum Cake {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ pub struct KeyValue {
```

:::info

Array datatype is supported for PostgreSQL, you can define a vector of any types that are already supported by SeaORM in the model. Keep in mind that you need to enable the `postgres-array` feature and this is a Postgres only feature.

Array datatype is a Postgres-only feature. You can define a vector of types that are already supported by SeaORM.
:::

```rust
Expand Down Expand Up @@ -157,22 +155,22 @@ If you specified a custom `column_type` for an optional attribute, you must also
pub name: Option<String>
```

### Ignore Attribute
### Cast Column Type on Select and Save

If you want to ignore a particular model attribute such that it maps to no database column, you can use the `ignore` annotation.
If you need to select a column as one type but save it into the database as another, you can specify the `select_as` and the `save_as` attributes to perform the casting. A typical use case is selecting a column of type `citext` (case-insensitive text) as `String` in Rust and saving it into the database as `citext`. One should define the model field as below:

```rust
#[sea_orm(ignore)]
pub ignore_me: String
#[sea_orm(select_as = "text", save_as = "citext")]
pub case_insensitive_text: String
```

### Cast Column Type on Select and Save
### Ignore Attribute

If you need to select a column as one type but save it into the database as another, you can specify the `select_as` and the `save_as` attributes to perform the casting. A typical use case is selecting a column of type `citext` (case-insensitive text) as `String` in Rust and saving it into the database as `citext`. One should define the model field as below:
If you want to ignore a particular model attribute such that it maps to no database column, you can use the `ignore` annotation.

```rust
#[sea_orm(select_as = "text", save_as = "citext")]
pub case_insensitive_text: String
#[sea_orm(ignore)]
pub ignore_me: String
```

## Primary Key
Expand All @@ -195,7 +193,7 @@ pub id: i32

### Composite Key

This is usually the case in junction tables, where a two-column tuple is used as the primary key. Simply annotate multiple columns to define a composite primary key. By default, `auto_increment` is `false` for composite key.
This is usually the case in junction tables, where a two-column tuple is used as the primary key. Simply annotate multiple columns to define a composite primary key. `auto_increment` is `false` for composite key.

The max arity of a primary key is 12.

Expand Down Expand Up @@ -233,7 +231,7 @@ Learn more about relations in the [Relation](06-relation/01-one-to-one.md) chapt

## Active Model Behavior

Handlers for different actions on an `ActiveModel`. For example, you can perform custom validation logic or trigger side effects. Inside a transaction, you can even abort an action after it is done, preventing it from saving into the database.
Hooks for different actions on an `ActiveModel`. For example, you can perform custom validation logic or trigger side effects. Inside a transaction, you can even abort an action after it is done, preventing it from saving into the database.

```rust
#[async_trait]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Data Loader

:::tip
If you are building a web API that queries nested relations extensively, consider building a GraphQL server. [Seaography](https://www.sea-ql.org/Seaography/) is a GraphQL framework for building GraphQL resolvers using SeaORM entities. Read "[Getting Started with Seaography](https://www.sea-ql.org/blog/2022-09-27-getting-started-with-seaography/)" to learn more.
:::

The [LoaderTrait](https://docs.rs/sea-orm/*/sea_orm/query/trait.LoaderTrait.html) provides an API to load related entities in batches.

Consider this one to many relation:
Expand Down Expand Up @@ -57,7 +53,7 @@ In an advanced use case, you can apply filters on the related entity:

```rust
let fruits_in_stock: Vec<Vec<fruit::Model>> = cakes.load_many(
fruit::Entity::find().filter(fruit::Column::Stock.gt(0i32))
fruit::Entity::find().filter(fruit::Column::Stock.gt(0i32)),
db
).await?;
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
You can unit test your application logic using the mock database interface.

:::info

Friendly reminder: you need to enable `mock` feature.

You need to enable the `mock` feature flag in Cargo.toml.
:::

The mock database has no data in it, so you have to define the expected data to be returned when CRUD operations are performed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ customer::ActiveModel {
.save(db)
.await?;

// The `notes` field was intentionally leaved out
// The `notes` field was intentionally left out
let customer = Customer::find()
.select_only()
.column(customer::Column::Id)
Expand Down

0 comments on commit e7490c6

Please sign in to comment.