Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of integrating with Rocket #106

Merged
merged 33 commits into from
Sep 3, 2021
Merged

Example of integrating with Rocket #106

merged 33 commits into from
Sep 3, 2021

Conversation

tyt2y3
Copy link
Member

@tyt2y3 tyt2y3 commented Aug 25, 2021

No description provided.

@tyt2y3 tyt2y3 marked this pull request as draft August 25, 2021 11:04
@billy1624
Copy link
Member

billy1624 commented Aug 25, 2021

Hey @samsamai, can you push the latest draft up here? Even if it can't be compiled.

@samsamai
Copy link
Contributor

samsamai commented Aug 25, 2021

Hi @tyt2y3 @billy1624 , yeah I've been trying to clean up the code up tonight but I'm having some weird problems, it is giving errors that I wasn't getting before. I just rebooted and updated rust... 🤞

@samsamai
Copy link
Contributor

Still doing it, it's weird, I'm going back to one of my commits from before but getting lots of these:

error[E0425]: cannot find function, tuple struct or tuple variant `ColumnFromStrErr` in module `sea_orm`
  --> /Users/sam/Code/github/sea-orm/src/tests_cfg/fruit.rs:20:40
   |
20 | #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
   |                                        ^^^^^^^^^^^^ not found in `sea_orm`
   |
   = note: this error originates in the derive macro `DeriveColumn` (in Nightly builds, run with -Z macro-backtrace for more info)

Not sure what it's doing with test_cfg when my code is a crate inside examples

@billy1624
Copy link
Member

Try cargo update

@samsamai
Copy link
Contributor

Thanks! that was it!

@samsamai
Copy link
Contributor

@billy1624 I pushed up the version that I have, sorry it is really messy as I was trying everything to just get it to work.
It needs this repo to run: git@github.com:samsamai/Rocket.git, branch: ss/seaorm-contrib so if you pull that down locally and change the examples/rocket_example/Cargo.toml and also contrib/db_pools/lib/Cargo.toml in this rocket repo, it should work locally.

cargo run in the rocket_example dir, and then http://127.0.0.1:8000/sqlx

It's hard coded to use mysql (see the rocket side) just to get it working.

@tyt2y3
Copy link
Member Author

tyt2y3 commented Aug 25, 2021

Okay, so that means we need to open a PR on Rocket!

@billy1624
Copy link
Member

Hey @samsamai, I think we can impl rocket_db_pools::Pool for sea_orm:: Database inside sea-orm without the need of forking rocket?

use rocket::figment::Figment;
use rocket_db_pools::{Config, Error};
#[rocket::async_trait]
impl rocket_db_pools::Pool for crate::Database {
type Error = crate::DbErr;
type Connection = crate::DatabaseConnection;
async fn init(figment: &Figment) -> Result<Self, Self::Error> {
// let config = figment.extract::<Config>()?;
// let mut opts = config.url.parse::<Options<D>>().map_err(Error::Init)?;
// opts.disable_statement_logging();
// specialize(&mut opts, &config);
// sqlx::pool::PoolOptions::new()
// .max_connections(config.max_connections as u32)
// .connect_timeout(Duration::from_secs(config.connect_timeout))
// .idle_timeout(config.idle_timeout.map(Duration::from_secs))
// .min_connections(config.min_connections.unwrap_or_default())
// .connect_with(opts)
// .await
// .map_err(Error::Init)
Ok(crate::Database {})
}
async fn get(&self) -> Result<Self::Connection, Self::Error> {
// self.acquire().await.map_err(Error::Get)
// let con = crate::Database::connect("sqlite::memory:").await;
// Ok(crate::Database::connect("sqlite::memory:").await.unwrap())
// "mysql://root:@localhost"
Ok(
crate::Database::connect("mysql://root:@localhost/rocket_example")
.await
.unwrap(),
)
}
}

@samsamai
Copy link
Contributor

Hey @samsamai, I think we can impl rocket_db_pools::Pool for sea_orm:: Database inside sea-orm without the need of forking rocket?

Thanks @billy1624 that's great, I was trying to do that but I was getting an error like only traits defined in the current crate can be implemented for arbitrary types, still not sure what I was doing wrong.

@tyt2y3
Copy link
Member Author

tyt2y3 commented Aug 26, 2021

Yes, because only the owner of the type or the trait can impl a trait for a type (well).
That means we should add a feature to SeaORM that imports the Rocket trait and impl it within SeaORM, then downstream can use that.

@tyt2y3
Copy link
Member Author

tyt2y3 commented Aug 28, 2021

Looks good so far. I am just puzzling, what's prevent us from generalizing over MySQL and Postgres?

@tyt2y3
Copy link
Member Author

tyt2y3 commented Aug 31, 2021

okay, I think we can name it sea_orm::RocketDbPool
@samsamai would you need help from @billy1624 on this?

@tyt2y3 tyt2y3 force-pushed the master branch 3 times, most recently from 2d2fff7 to 6847dab Compare August 31, 2021 08:02
@samsamai
Copy link
Contributor

@tyt2y3 Yes sure, @billy1624 help is always appreciated. I'll make a start on it and ask if I get stuck.

@tyt2y3
Copy link
Member Author

tyt2y3 commented Sep 1, 2021

Looks really good now!
@samsamai is there still anything missing?
@billy1624 what's your thought?

@samsamai
Copy link
Contributor

samsamai commented Sep 2, 2021

I've been adding some templates so that the example renders html and is more interactive. I will check that in soon and then have a look at getting db_url in the run_migrations.

@billy1624
Copy link
Member

Wow we got an UI for it? Cool! @samsamai

@tyt2y3
Copy link
Member Author

tyt2y3 commented Sep 3, 2021

I think we are missing a link in the /list to /read the post?

@tyt2y3 tyt2y3 marked this pull request as ready for review September 3, 2021 11:32
@samsamai samsamai changed the title Ss/rocket example Example of integrating with Rocket Sep 3, 2021
@samsamai
Copy link
Contributor

samsamai commented Sep 3, 2021

@tyt2y3 I added an edit page which serves dual purpose.

@samsamai
Copy link
Contributor

samsamai commented Sep 3, 2021

This is ready to launch, I reckon. 😉

@tyt2y3
Copy link
Member Author

tyt2y3 commented Sep 3, 2021

image

@tyt2y3 tyt2y3 merged commit a5db07c into master Sep 3, 2021
@tyt2y3 tyt2y3 deleted the ss/rocket-example branch September 3, 2021 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rocket example
3 participants