Skip to content

Commit 39c6536

Browse files
authored
docs: Add documentation supporting native, asynchronous database operations (#580)
* feat: add sea orm documents * feat: add description for sea orm cli
1 parent 2932f90 commit 39c6536

File tree

8 files changed

+1421
-109
lines changed

8 files changed

+1421
-109
lines changed

docs/databases.md

+18
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,23 @@ This example also maps the error to an `HttpResponse` before using the `?` opera
3232

3333
That's it! See the full example [here](https://github.com/actix/examples/tree/master/databases/diesel).
3434

35+
# SeaORM
36+
37+
[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`.
38+
39+
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:
40+
41+
<CodeBlock example="sea-orm-databases" file="main.rs" section="handler" />
42+
43+
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:
44+
45+
<CodeBlock example="sea-orm-databases" file="main.rs" section="main" />
46+
47+
In your request handler, use the `web::Data<DatabaseConnection>` extractor to get the database connection and perform async operations directly:
48+
49+
<CodeBlock example="sea-orm-databases" file="main.rs" section="index" />
50+
51+
For a full example, please refer to [here](https://github.com/actix/examples/tree/master/databases/sea-orm).
52+
3553
[web-block]: https://docs.rs/actix-web/4/actix_web/web/fn.block.html
3654
[response-error]: https://docs.rs/actix-web/4/actix_web/error/trait.ResponseError.html

0 commit comments

Comments
 (0)