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

Trait error using sqlx example #204

Closed
nk9 opened this issue Mar 16, 2024 · 9 comments
Closed

Trait error using sqlx example #204

nk9 opened this issue Mar 16, 2024 · 9 comments

Comments

@nk9
Copy link
Contributor

nk9 commented Mar 16, 2024

I'm using the SQLX geo-types example, and it's failing. Has the required code changed?

use geo::{Geometry, Point};

let geom: Geometry<f64> = Point::new(10.0, 20.0).into();
let _ = sqlx::query(
    "INSERT INTO point2d (datetimefield,geom) VALUES(now(),ST_SetSRID($1,4326))",
)
.bind(wkb::Encode(geom))
.execute(&pool)
.await?;
 1  error[E0277]: the trait bound `geozero::wkb::Encode<geo::Geometry>: sqlx::Encode<'_, _>` is not satisfied
    --> rust/load_all.rs:245:19
     |
 245 |             .bind(wkb::Encode(geom))
     |              ---- ^^^^^^^^^^^^^^^^^ the trait `sqlx::Encode<'_, _>` is not implemented for `geozero::wkb::Encode<geo::Geometry>`
     |              |
     |              required by a bound introduced by this call
     |
     = help: the following other types implement trait `sqlx::Encode<'q, DB>`:
               <bool as sqlx::Encode<'q, sqlx::Any>>
               <bool as sqlx::Encode<'_, Postgres>>
               <i8 as sqlx::Encode<'_, Postgres>>
               <i16 as sqlx::Encode<'q, sqlx::Any>>
               <i16 as sqlx::Encode<'_, Postgres>>
               <i32 as sqlx::Encode<'q, sqlx::Any>>
               <i32 as sqlx::Encode<'_, Postgres>>
               <i64 as sqlx::Encode<'q, sqlx::Any>>
             and 34 others
 note: required by a bound in `Query::<'q, DB, <DB as HasArguments<'q>>::Arguments>::bind`
    --> /Users/nick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.3/src/query.rs:79:32
     |
 79  |     pub fn bind<T: 'q + Send + Encode<'q, DB> + Type<DB>>(mut self, value: T) -> Self {
     |                                ^^^^^^^^^^^^^^ required by this bound in `Query::<'q, DB, <DB as HasArguments<'q>>::Arguments>::bind`
@nk9
Copy link
Contributor Author

nk9 commented Mar 16, 2024

Ah, this works if you install the required feature:

cargo add geozero --features with-postgis-sqlx

Is it possible to provide an error that points out the problem in this situation? I'm sure I've seen other crates where the compiler suggests adding the feature(s) that contain the code needed to make yours compile. Either way, it would be great if this requirement were mentioned in the README.

@michaelkirk
Copy link
Member

michaelkirk commented Mar 16, 2024 via email

@nk9
Copy link
Contributor Author

nk9 commented Mar 16, 2024

Here's an example, not sure if it's applicable? The error looks like this:

error: The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled.
  --> rust/load_all.rs:32:1
   |
32 | #[tokio::main]
   | ^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `tokio::main` (in Nightly builds, run with -Z macro-backtrace for more info)

You can see it for yourself by installing tokio with no features and creating a file with just this code:

#[tokio::main]
async fn main() -> Result<()> {
    Ok(())
}

@michaelkirk
Copy link
Member

Oh that's nice. Looking at that example, it's within the context of a procedural macro, so I don't think we can use that technique. I wonder if it's possible outside of that context.

@sergiomeneses
Copy link
Contributor

sergiomeneses commented Jul 25, 2024

I upgrade sqlx from 0.7.4 to 0.8.0 and get this error even using with-postgis-sqlx feature.

@sergiomeneses
Copy link
Contributor

sergiomeneses commented Jul 26, 2024

The specific error is this:

the trait bound `geozero::wkb::Decode<geo::Geometry>: sqlx::Decode<'_, _>` is not satisfied
the following other types implement trait `sqlx::Decode<'r, DB>`:
  <bool as sqlx::Decode<'r, sqlx::Any>>
  <bool as sqlx::Decode<'_, Postgres>>
  <i8 as sqlx::Decode<'_, Postgres>>
  <i16 as sqlx::Decode<'r, sqlx::Any>>
  <i16 as sqlx::Decode<'_, Postgres>>
  <i32 as sqlx::Decode<'r, sqlx::Any>>
  <i32 as sqlx::Decode<'_, Postgres>>
  <i64 as sqlx::Decode<'r, sqlx::Any>>
and 62 othersrustc

I think the cause is by this breaking change

@abonander
Copy link

I upgrade sqlx from 0.7.4 to 0.8.0 and get this error even using with-postgis-sqlx feature.

That's because you upgraded to 0.8.0. It's a non-compatible version. geozero needs to cut a new release to match.

@sergiomeneses
Copy link
Contributor

Thanks i made a new issue about this #223

@CommanderStorm
Copy link

Since #223 was merged and works (only waiting for a new release)
I think this issue is resolved and can be closed.

Patch for others looking at this issue

[patch.crates-io]
# needs release after 0.13
# https://github.com/georust/geozero/tags
geozero = { git = "https://github.com/georust/geozero.git", rev = "f8ab4363b0660cd84a58212039651fd68c3a8567" }

@pka pka closed this as completed Sep 26, 2024
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

No branches or pull requests

6 participants