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

Updated dependencies to use diesel 2.0.0-rc.0 and sqlx 0.6.0 #2242

Closed
wants to merge 12 commits into from

Conversation

pintariching
Copy link

I have updated the dependency for sqlx from 0.5 to 0.6, but to do that, diesel also needs to be updated to the latest release candidate as I get an issue about sqlx and diesel using different versions of libsqlite-sys
The tests for --contrib all pass but some --example test fail, they would probably have to be updated too.

It might be better to wait for diesel 2.0.0 to released fully but this works as a stopgap.

As said in #2209, a feature flag should be also implemented but I think both diesel and sqlx have to be updated at once

@pintariching
Copy link
Author

Okay I just tested it, diesel can be updated to 2.0.0-rc.0 without a problem, but for sqlx to be updated to 0.6, diesel also needs to be updated otherwise I get this chunky error:

error: failed to select a version for `libsqlite3-sys`.
    ... required by package `sqlx-core v0.6.0`
    ... which satisfies dependency `sqlx-core = "^0.6.0"` of package `sqlx v0.6.0`
    ... which satisfies dependency `sqlx = "^0.6"` of package `rocket_db_pools v0.1.0-rc.2 (/home/tilen/Documents/Rocket/contrib/db_pools/lib)`
    ... which satisfies path dependency `rocket_db_pools` (locked to 0.1.0-rc.2) of package `rocket_db_pools_codegen v0.1.0-rc.2 (/home/tilen/Documents/Rocket/contrib/db_pools/codegen)`
versions that meet the requirements `^0.24.1` are: 0.24.2, 0.24.1

the package `libsqlite3-sys` links to the native library `sqlite3`, but it conflicts with a previous package which links to `sqlite3` as well:
package `libsqlite3-sys v0.22.2`
    ... which satisfies dependency `libsqlite3-sys = "^0.22.2"` of package `rusqlite v0.25.4`
    ... which satisfies dependency `rusqlite = "^0.25"` of package `r2d2_sqlite v0.18.0`
    ... which satisfies dependency `r2d2_sqlite = "^0.18.0"` of package `rocket_sync_db_pools v0.1.0-rc.2 (/home/tilen/Documents/Rocket/contrib/sync_db_pools/lib)`
    ... which satisfies path dependency `rocket_sync_db_pools` (locked to 0.1.0-rc.2) of package `rocket_sync_db_pools_codegen v0.1.0-rc.2 (/home/tilen/Documents/Rocket/contrib/sync_db_pools/codegen)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the links ='libsqlite3-sys' value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `libsqlite3-sys` which could resolve this conflict

@pintariching
Copy link
Author

Now I get the following error when trying to use .fetch_all with sqlx

.fetch_all(&mut *db)
---------- ^^^^^^^^ the trait `sqlx::Executor<'_>` is not implemented for `&mut rocket_db_pools::sqlx::pool::PoolConnection<rocket_db_pools::sqlx::Postgres>`

The entire function looks like this

#[get("/tags")]
pub async fn fetch(
  db: Connection<Db>
) -> Result<Json<Vec<Tag>>, Status> {
  sqlx::query_as!(Tag, "SELECT id, label, color FROM tag ORDER BY id")
    .fetch_all(&db)  // < -- error underlines this
    .await
    .map(|tag| Json(tag))
    .map_err(Status::InternalServerError)
  )
}

I'm not sure where to continue

@pintariching pintariching changed the title Updated dependencies for to use diesel 2.0.0-rc.0 and sqlx 0.6.0 Updated dependencies to use diesel 2.0.0-rc.0 and sqlx 0.6.0 Jun 21, 2022
@pintariching
Copy link
Author

Now I get the following error when trying to use .fetch_all with sqlx

.fetch_all(&mut *db)
---------- ^^^^^^^^ the trait `sqlx::Executor<'_>` is not implemented for `&mut rocket_db_pools::sqlx::pool::PoolConnection<rocket_db_pools::sqlx::Postgres>`

The entire function looks like this

#[get("/tags")]
pub async fn fetch(
  db: Connection<Db>
) -> Result<Json<Vec<Tag>>, Status> {
  sqlx::query_as!(Tag, "SELECT id, label, color FROM tag ORDER BY id")
    .fetch_all(&db)  // < -- error underlines this
    .await
    .map(|tag| Json(tag))
    .map_err(Status::InternalServerError)
  )
}

I'm not sure where to continue

Okay I don't know what happened, I started a new project to reproduce the error but it didn't work, then I tried to build my main project and it also worked for some reason. If anybody wants to check it out I have a repo here: https://github.com/pintariching/docrab-api

@yzernik
Copy link

yzernik commented Jun 26, 2022

Were you able to get the example "databases" app working here?
https://github.com/SergioBenitez/Rocket/tree/master/examples/databases

@pintariching
Copy link
Author

I get the example to work if I comment out the migrations. diesel_migrations has been completely rewritten and I haven't figured out the migration part yet.

@iamcodemaker
Copy link

This will also fix an issue with the sqlx::FromSql in which sqlx v0.5 depends on uuid v0.8.2 and implements traits for the types in that crate but rocket_db_pools depends on uuid v1 so the two crates implement traits on different types. sqlx v0.6 depends on uuid v1 and resolves this problem.

@iamcodemaker
Copy link

I figured out the migrations issue: pintariching#1

pintariching and others added 2 commits July 13, 2022 14:11
fix migrations in diesel_sqlite example code
@pintariching
Copy link
Author

Okay the examples now build and test without errors. I've also updated the todo example a bit.

@Taiwing
Copy link

Taiwing commented Jul 26, 2022

Hey! I just ran into a problem that this pull request will solve (the two different uuid versions, as mentioned above). Do you guys know when it could be merged ?

@harryssecret
Copy link

How does the sqlx example even works ? The rocket_db_pools implementation of sqlx is still in 0.5. That's what i'm getting when using it in 0.6 (not on this example tho) apparently because the rocket types aren't up to date with the latest sqlx ver?
the trait sqlx::Executor<'_>` is not implemented for `&mut rocket_db_pools::sqlx::pool::PoolConnection<rocket_db_pools::sqlx::Postgres>

@pintariching
Copy link
Author

I think I updated the sqlx version in rocket_db_pools to 0.6.0 also. So the examples database and todo should both work I think.

@julien-me
Copy link

Any update on when this PR can be merged? There's a bugfix on sqlx 0.6 that I'd need.

@pintariching
Copy link
Author

I think SQLx and Diesel can now be updated to both 0.6.1 and 2.0.0 respectivley as they have both been updated by now

@SergioBenitez
Copy link
Member

Awesome, let's give this a whirl. Unfortunately UI tests are flaky, so we may get a failure. It's probably time to remove them, or somehow not depend on them, entirely.

@SergioBenitez
Copy link
Member

Merged in f0d678d with a few fixes. Thank you so much for this! Extraordinarily helpful.

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.

None yet

7 participants