Rocket
Rocket copied to clipboard
Updated dependencies to use diesel 2.0.0-rc.0 and sqlx 0.6.0
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
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
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
Now I get the following error when trying to use
.fetch_all
withsqlx
.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
Were you able to get the example "databases" app working here? https://github.com/SergioBenitez/Rocket/tree/master/examples/databases
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.
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.
I figured out the migrations issue: pintariching/Rocket#1
Okay the examples now build and test without errors. I've also updated the todo example a bit.
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 ?
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>
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.
Any update on when this PR can be merged? There's a bugfix on sqlx
0.6 that I'd need.
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
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.
Merged in f0d678d464e776aaaf5d7d5f1d30df3422d362f9 with a few fixes. Thank you so much for this! Extraordinarily helpful.