Closed dwight9339 closed 3 months ago
That runtime error implies that it's being passed a &str
rather than a &PgLayerType
value.
Thanks for your response. I tried passing &PgLayerType::Dense
directly and that still didn't work. I tried implementing ToSql
myself but that didn't help either:
impl ToSql for PgLayerType {
fn to_sql(&self, _ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
match *self {
Self::Sparse => out.extend_from_slice(b"sparse"),
Self::Dense => out.extend_from_slice(b"dense")
};
Ok(IsNull::No)
}
fn accepts(ty: &Type) -> bool {
ty.name() == "layer_type"
}
to_sql_checked!();
}
I built a statement out of the query string and printed out the types if that's at all helpful:
Statement types: [Uuid, Int4, Int4, Varchar, Text, Other(Other { name: "layer_type", oid: 19728, kind: Enum(["sparse", "dense"]), schema: "public" })]
If it's still complaining about the type being &str
then it's probably happening in a different query than the one you're editing.
Ah, you're right. The error was happening in my Layer::try_from()
method. Thanks again.
Alright, I've been trying to figure out what I'm doing wrong for the better part of a day now and am still struggling. Here is my custom enum in Postgres:
And here is my struct declaration:
I know it looks funky but I'm using Diesel for DB ops that can run in sync and tokio_postgres for async ops. I had originally tried just adding
ToSql
andFromSql
to the list of derives and the postgres macro to the the existing enum type which is used by Diesel but tried separating them and implementingFrom
for conversion because I thought maybe the derive function from thediesel_derive_enum
might be causing some issue when mixed with the postgres_types derives but separating them has not yielded any different results so far.Here is the code where I'm attempting to insert a row containing the enum in question:
I'm still getting this error though: