I'm trying retrieve all points of interest stored in my DB, with the following DB schema:
CREATE TABLE elements (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
collection_id uuid NOT NULL,
name TEXT NOT NULL,
description TEXT,
CONSTRAINT fk_elements_collections FOREIGN KEY(collection_id) REFERENCES collections(id) ON DELETE CASCADE
);
CREATE TABLE points (
element_id uuid PRIMARY KEY NOT NULL,
point geometry(Point,4326) NOT NULL,
CONSTRAINT fk_points_elements FOREIGN KEY(element_id) REFERENCES elements(id) ON DELETE CASCADE
);
That it's translated to diesel schema as:
diesel::table! {
use diesel::sql_types::*;
use diesel::pg::sql_types::*;
use postgis_diesel::sql_types::*;
elements (id) {
id -> Uuid,
collection_id -> Uuid,
name -> Text,
description -> Nullable<Text>,
}
}
diesel::table! {
use diesel::sql_types::*;
use diesel::pg::sql_types::*;
use postgis_diesel::sql_types::*;
use super::sql_types::Geometry;
points (element_id) {
element_id -> Uuid,
point -> Geometry,
}
}
I'm trying to query all the points that are part of a collection with this code:
use diesel::Queryable;
use postgis_diesel::types::Point;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Queryable)]
pub struct PointOfInterest {
pub id: uuid::Uuid,
pub collection_id: uuid::Uuid,
pub name: String,
pub description: Option<String>,
pub point: Point,
}
elements::table
.inner_join(points::table)
.filter(elements::collection_id.eq(collection))
.select((
elements::id,
elements::collection_id,
elements::name,
elements::description,
points::point,
))
.load::<PointOfInterest>(connection)
But I'm getting this error:
error[E0277]: the trait bound `(diesel::sql_types::Uuid, diesel::sql_types::Uuid, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>, schema::sql_types::Geometry): load_dsl::private::CompatibleType<PointOfInterest, Pg>` is not satisfied
--> src/domain/points/repo.rs:43:46
|
43 | .load::<PointOfInterest>(connection)
| ---- ^^^^^^^^^^ the trait `load_dsl::private::CompatibleType<PointOfInterest, Pg>` is not implemented for `(diesel::sql_types::Uuid, diesel::sql_types::Uuid, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>, schema::sql_types::Geometry)`
| |
| required by a bound introduced by this call
|
For what I've tested, if I remove the point
field of my PointOfInterest
struct and from the select
statement, I do get things to work.
After almost a week of investigation, and after reading among some others, this two answers about this issue:
- Rust diesel the trait `load_dsl::private::CompatibleType<PodcastEpisode, Sqlite>` is not implemented for `Untyped
- Rust Diesel, error loading results of a sql_query that select columns from multiple tables
I came to the conclusion that the Point
type that I'm using from the diesel_postgis
library must be missing a trait, but I'm unable to make any progress on this regard.
Could somebody give me a hand in trying to figure out how to get from here?
Relevant versions:
diesel = { version = "2.1.0", features = ["postgres", "uuid"] }
postgis_diesel = { version = "2.1.0", features = ["serde"] }
uuid = { version = "1.2.1", features = ["serde", "v7"] }
serde = { version = "1.0.136", features = ["derive"] }