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

Add support for diesel 2.0.0 #2209

Closed
CuriousCI opened this issue May 29, 2022 · 3 comments
Closed

Add support for diesel 2.0.0 #2209

CuriousCI opened this issue May 29, 2022 · 3 comments
Labels
suggestion A suggestion to change functionality

Comments

@CuriousCI
Copy link

Existing Functionality

rocket_sync_db_pools currently relies on diesel 1.4, which is going out of support, and it's currently giving some problems with uuid 1.0.0.

  • diesel 1.4 supports up to uuid 0.8 and rocket 0.5.0-rc has functionalities for uuid 1.0, creating a conflict: if I want to use uuid::Uuid in the models, I must use version 0.8, but, if I want a uuid in a route, I must use rocket::serde::uuid::Uuid, which isn't compatible with the diesel implementation. To handle this problem, I downgraded the uuid version to 0.8, and created a conversion function:
pub fn to_uuid(id: rocket::serde::uuid::Uuid) -> Result<uuid::Uuid, uuid::Error> {
    Uuid::parse_str(id.to_string().as_str())
}

Which means I must manually use it everytime I want to use a Uuid in a request_:

#[get("/<id>")]
pub async fn get_id(id: rocket::serde::uuid::Uuid, db: Db) -> Json<User> {
    let id = to_uuid(id).unwrap();
    
    ...
}
  • It also means that I have to handle 2 Uuids in my code, which can be confusing in some parts.
  • The other problem is that the 1.4.x won't be supported anymore, so it would be really useful to transition to 2.0.0 as soon as it's ready.
  • The current version is missing some of the new functionalities like group by, table aliasing, "Selectable" trait, union, intersect and except.

A clear and concise description of existing functionality and why it is insufficient. Examples:

Suggested Changes

I still haven't looked at the code to find a solution, and it would still be too soon to upgrade to the new version, as it's not fully ready yet.

Alternatives Considered

I've tried to implement the Poolable trait for diesel 2.0.0's PgConnection inside my project, but it's really complex, as I can't directly implement the trait to diesel::PgConnection due to the orphan rule.

I can implement Poolable only if I wrap diesel::PgConnection with a custom struct

pub struct Connection(diesel::PgConnection); 

But I manually have to implement a custom manager, and all the other traits diesel:PgConnection uses.

impl Poolable for Connection {
    type Manager = ....;
    ...
}

Additional Context

diesel 2.0.0 it's still not ready, I suggest waiting before trying to implement anything. I would also be glad to hear some suggestions, or the problems this feature can create.

@CuriousCI CuriousCI added the suggestion A suggestion to change functionality label May 29, 2022
@SergioBenitez
Copy link
Member

I'd be in favor of adding support under a diesel-2 feature flag or similar, leaving the current support in tact. Please submit a PR doing so, using the existing implementation and docs for diesel's present support as a baseline for this implementation. Remember to update all relevant docs including the crate-level docs indicating support for this feature and any relevant guide docs.

@CuriousCI
Copy link
Author

diesel-2 is a good enough name, I'll work on the PR.

@RalfNorthman
Copy link

Diesel 2.0.0 is now official!

https://crates.io/crates/diesel

dyc3 added a commit to dyc3/d6-survey-service that referenced this issue Feb 9, 2023
The fix for using postgres and diesel 2 has not been published as a new version of the crate yet, so we are at the whims of the current master branch
rwf2/Rocket#2209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion A suggestion to change functionality
Projects
None yet
Development

No branches or pull requests

3 participants