当我试图像这样定义rust diesel diesel = { version = "2.1.0", features = [ "postgres", "64-column-tables", "chrono", "serde_json", ] }
插入模型时:
#![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
}
字符串
编译器显示错误:
~/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>`
型
如何在rust diesel中定义PostgreSQL二进制数据?
1条答案
按热度按时间ryoqjall1#
不要在结构中使用任何
diesel::sql_types::*
;它们只是在其他调用中使用的标记,用于指示要使用的SQL类型(而不是Rust类型)。您需要
Vec<u8>
;Bytea
是diesel::sql_types::Binary
的别名,表示对应的ToSql
/FromSql
类型为Vec<u8>
。