[Rust SeaORM FAQs] SeaORM integrate Rocket support

sea-orm-rocket

sea-orm-rocket is the crate for SeaORM integrate Rocket support.

SeaORM is a relational ORM to help you build light weight and concurrent web services in Rust

Rocket is a web framework for Rust. If youโ€™d like, you can think of Rocket as being a more flexible, friendly medley of Rails - https://rubyonrails.org/, Flask - https://palletsprojects.com/p/flask/, Bottle - https://bottlepy.org/docs/dev/index.html, and Yesod - https://www.yesodweb.com/. We prefer to think of Rocket as something new. Rocket aims to be fast, easy, and flexible while offering guaranteed safety and security where it can. Importantly, Rocket also aims to be fun, and it accomplishes this by ensuring that you write as little code as needed to accomplish your task.

Usages

Download

1
2
3
$ git clone [email protected]:SeaQL/sea-orm.git

$ cd sea-orm/examples/rocket_example

Config Database

Replace url with your prefered Database url.

1
2
3
4
5
# Rocket.toml

- url = "postgres://root:root@localhost/rocket_example"
+ # url = "postgres://root:root@localhost/rocket_example"
+ url = "postgres://<Your PostgreSQL User Name>:<Your PostgreSQL Password>@postgres:5432/<Your PostgreSQL Database>"

Cargo Run

1
$ cargo run

Then, ๐Ÿš€ Rocket has launched from http://127.0.0.1:8000.

See sea-orm/examples/rocket_example at master ยท SeaQL/sea-orm - https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_example to learn more.

FAQs

perhaps two different versions of crate rocket are being used?

1
2
3
4
5
6
7
8
9
error[E0308]: mismatched types
--> src/pool.rs:8:12
|
8 | pub struct Db(SeaOrmPool);
| ^^ expected struct `sea_orm_rocket:🚀:Rocket`, found struct `rocket::Rocket`
|
= note: expected reference `&sea_orm_rocket:🚀:Rocket<_>`
found reference `&rocket::Rocket<rocket::Ignite>`
= note: perhaps two different versions of crate `rocket` are being used?

Remember to make rocket and sea-orm compatible.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Cargo.toml

[dependencies.rocket]
version = "0.5.0-rc.1"
# git = "https://github.com/SergioBenitez/Rocket.git"
features = ["json"]

# Database & Asy`env_logger`nc Runtime | SeaORM - ๐Ÿš An async & dynamic ORM for Rust
# https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime
[dependencies.sea-orm]
version = "^0.5.0"
# version = "^0"
# git = "https://github.com/SeaQL/sea-orm"
features = ["debug-print", "macros", "sqlx-postgres", "runtime-tokio-native-tls"]
default-features = false

[dependencies.sea-orm-rocket]
# path = "../../sea-orm-rocket/lib" # remove this line in your own project and use the git line
git = "https://github.com/SeaQL/sea-orm"

the trait Clone is not implemented for DatabaseConnection

1
2
3
11  | pub struct SeaOrmPool {
12 | pub conn: sea_orm::DatabaseConnection,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `DatabaseConnection`

Check DatabaseConnection source code:

1
2
3
4
// sea-orm/src/database/db_connection.rs

#[cfg_attr(not(feature = "mock"), derive(Clone))]
pub enum DatabaseConnection {

Remember to disable mock feature to enable derive(Clone) for DatabaseConnection.

1
2
3
4
5
6
7
# Cargo.toml

[dependencies.sea-orm]
path = "../../" # remove this line in your own project
version = "^0.5.0"
features = ["macros", "runtime-async-std-native-tls", "debug-print"]
+ default-features = false

References

[1] sea-orm/examples/rocket_example at master ยท SeaQL/sea-orm - https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_example

[2] sea-orm/sea-orm-rocket at master ยท SeaQL/sea-orm - https://github.com/SeaQL/sea-orm/tree/master/sea-orm-rocket

[3] SeaORM - ๐Ÿš An async & dynamic ORM for Rust - https://www.sea-ql.org/SeaORM/

[4] SeaQL/sea-orm: ๐Ÿš An async & dynamic ORM for Rust - https://github.com/SeaQL/sea-orm

[5] Getting Started - Rocket Programming Guide - https://rocket.rs/v0.5-rc/guide/getting-started/

[6] Rocket - Simple, Fast, Type-Safe Web Framework for Rust - https://rocket.rs/