I am getting an error on the .first::(connection), connection object. I am assuming NaiveDateTime is not correct? Below is the diesel table and code
diesel::table! {
artists (id) {
id -> Uuid,
created_at -> Timestamp,
name -> Varchar,
public_key -> Varchar,
price_per_art_usdc -> Numeric,
description -> Text,
image_url -> Text,
}
}
use crate::routes::create_commission_request::ApiError;
use crate::{database::lib::establish_connection, payload::create_response_success};
use axum::{http::StatusCode, response::IntoResponse, Json};
use chrono::NaiveDateTime;
use diesel::prelude::*;
use serde::{Deserialize, Serialize};
use serde_json::json;
#[derive(Queryable, Debug, Serialize)]
#[diesel(table_name = artists)]
struct ArtistSelect {
name: String,
public_key: String,
description: String,
created_at: NaiveDateTime,
image_url: String,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Payload {
public_key: String,
}
#[axum::debug_handler]
pub async fn handle(Json(payload): Json) -> Result<impl IntoResponse, ApiError> {
use crate::database::schema::artists::dsl::*;
let connection = &mut establish_connection();
let artist = artists
.filter(public_key.eq(public_key))
.select((name, public_key, description, created_at, image_url))
.first::(connection)
.map_err(|_| ApiError::NotFound("Artist not found".to_string()))?;
let response = create_response_success(json!(artist), "Artist found");
Ok((StatusCode::OK, Json(response)))
}
the trait bound (diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Timestamp, diesel::sql_types::Text): load_dsl::private::CompatibleType<ArtistSelect, _>
is not satisfied
the full name for the type has been written to '/Users/hankchen/Code/hellomoon/mosaiq-exchange-contract/target/debug/deps/server-736dd96d25d5863e.long-type-9516133194885964663.txt'
consider using --verbose
to print the full type name to the console
this is a mismatch between what your query returns and what your type expects the query to return
the fields in your struct need to match the fields returned by your query in count, order and type
consider using #[derive(Selectable)]
or #[derive(QueryableByName)] + #[diesel(check_for_backend(_))]
on your struct ArtistSelect
and in your query .select(ArtistSelect::as_select())
to get a better error message
the following other types implement trait load_dsl::private::CompatibleType<U, DB>
:
(ST0, ST1)
(ST0, ST1, ST2)
(ST0, ST1, ST2, ST3)
(ST0, ST1, ST2, ST3, ST4)
(ST0, ST1, ST2, ST3, ST4, ST5)
(ST0, ST1, ST2, ST3, ST4, ST5, ST6)
(ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7)
(ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7, ST8)
and 24 others
required for SelectStatement<FromClause<table>, ..., ..., ..., ..., ...>
to implement LoadQuery<'_, _, ArtistSelect>
the full name for the type has been written to '/Users/hankchen/Code/hellomoon/mosaiq-exchange-contract/target/debug/deps/server-736dd96d25d5863e.long-type-757238791635730012.txt'
consider using --verbose
to print the full type name to the consolerustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic message [0]?0#file:///Users/hankchen/Code/hellomoon/mosaiq-exchange-contract/server/src/routes/artist/get_application.rs)
get_application.rs(32, 10): required by a bound introduced by this call
mod.rs(1779, 22): required by a bound in first
1 post - 1 participant
Source: View source