When I tried to define the rust diesel diesel = { version = "2.1.0", features = [ "postgres", "64-column-tables", "chrono", "serde_json", ] }
insert model like this:
#![allow(unused)]
#![allow(clippy::all)]
use std::ffi::OsString;
use actix_multipart::form::tempfile::TempFile;
use diesel::sql_types::Bytea;
use rust_wheel::common::util::time_util::get_current_millisecond;
use rust_wheel::model::user::login_user_info::LoginUserInfo;
use serde::Serialize;
use serde::Deserialize;
use uuid::Uuid;
use crate::model::diesel::tex::custom_tex_models::TexTemplate;
use crate::model::diesel::tex::tex_schema::*;
use crate::model::request::file::add::file_add_req::TexFileAddReq;
use crate::model::request::file::add::file_add_ver_req::TexFileVerAddReq;
#[derive(Insertable,Queryable,QueryableByName,Debug,Serialize,Deserialize,Default,Clone)]
#[diesel(table_name = tex_file_version)]
pub struct TexFileVersionAdd {
pub name: String,
pub created_time: i64,
pub updated_time: i64,
pub user_id: i64,
pub project_id: String,
pub file_id: String,
pub content: String,
pub snapshot: Bytea
}
the compiler shows error:
~/source/reddwarf/backend/texhub-server on main! ⌚ 12:29:48
$ cargo b ‹ruby-2.7.2›
Compiling texhub-server v0.1.0 (/Users/dolphin/source/reddwarf/backend/texhub-server)
error[E0277]: the trait bound `diesel::sql_types::Binary: diesel::Expression` is not satisfied
--> src/model/diesel/tex/custom_tex_models.rs:107:9
|
107 | pub snapshot: Bytea,
| ^^^^^^^^ the trait `diesel::Expression` is not implemented for `diesel::sql_types::Binary`
|
= help: the following other types implement trait `diesel::Expression`:
&'a T
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
(T0, T1, T2, T3, T4, T5)
(T0, T1, T2, T3, T4, T5, T6)
(T0, T1, T2, T3, T4, T5, T6, T7)
and 240 others
= note: required for `diesel::sql_types::Binary` to implement `AsExpression<diesel::sql_types::Binary>`
what should I do to define the PostgreSQL binary data in rust diesel?
Don't use any of the diesel::sql_types::*
in your structs; they are only markers for use in other calls to indicate what SQL type (not Rust type) to use.
You want Vec<u8>
instead; Bytea
is an alias for diesel::sql_types::Binary
which says the corresponding ToSql
/FromSql
type would be Vec<u8>
.