postgresql trait `diesel::Expression`未为`diesel::sql_types::Binary`实现

0s0u357o  于 6个月前  发布在  PostgreSQL
关注(0)|答案(1)|浏览(75)

当我试图像这样定义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二进制数据?

ryoqjall

ryoqjall1#

不要在结构中使用任何diesel::sql_types::*;它们只是在其他调用中使用的标记,用于指示要使用的SQL类型(而不是Rust类型)。
您需要Vec<u8>; Byteadiesel::sql_types::Binary的别名,表示对应的ToSql/FromSql类型为Vec<u8>

相关问题