1
0
mirror of https://github.com/actix/actix-website synced 2025-06-26 23:27:43 +02:00

docs: Add documentation supporting native, asynchronous database operations (#580)

* feat: add sea orm documents

* feat: add description for sea orm cli
This commit is contained in:
penysho
2025-04-07 04:21:35 +09:00
committed by GitHub
parent 2932f90e2b
commit 39c65361b2
8 changed files with 1356 additions and 44 deletions

View File

@ -32,5 +32,23 @@ This example also maps the error to an `HttpResponse` before using the `?` opera
That's it! See the full example [here](https://github.com/actix/examples/tree/master/databases/diesel).
# SeaORM
[SeaORM](https://www.sea-ql.org/SeaORM/) is a Rust ORM with full async support. When used with Actix Web, unlike Diesel, it allows you to perform database operations directly in an asynchronous manner without needing to use `web::block`.
First, define your data models and functions for database operations. Using `sea-orm-cli`, you can use a data model that is automatically generated from an existing DB definition:
<CodeBlock example="sea-orm-databases" file="main.rs" section="handler" />
Next, set up the database connection as part of your application state. SeaORM manages connection pools by default, so you don't need additional pool configuration:
<CodeBlock example="sea-orm-databases" file="main.rs" section="main" />
In your request handler, use the `web::Data<DatabaseConnection>` extractor to get the database connection and perform async operations directly:
<CodeBlock example="sea-orm-databases" file="main.rs" section="index" />
For a full example, please refer to [here](https://github.com/actix/examples/tree/master/databases/sea-orm).
[web-block]: https://docs.rs/actix-web/4/actix_web/web/fn.block.html
[response-error]: https://docs.rs/actix-web/4/actix_web/error/trait.ResponseError.html