如何将 i64 与 Insertable 一起使用,可在 pg 中使用 Diesel 进行查询

问题描述

如何在 Diesel 中使用 i64/u64 和其他原始类型?

sqlite 中可以,但在 postgres RDBMS 中不行

这是我的代码

cargo.toml:


[dependencies]
diesel = { version = "1.2.2",features = ["postgres","chrono","num-bigint","bigdecimal","num-traits","num-integer"] }
bigdecimal = "*"

CREATE TABLE Trades
(
    id              SERIAL PRIMARY KEY,price           integer,seller_fee      NUMERIC NOT NULL,buyer_fee       NUMERIC NOT NULL,created_at      TIMESTAMP,updated_at      TIMESTAMP
)

schema.rs:


table! {
    Trades (id) {
        id -> Int4,price -> Nullable<Int4>,seller_fee -> Numeric,buyer_fee -> Numeric,created_at -> Nullable<Timestamp>,updated_at -> Nullable<Timestamp>,}
}

#[derive(Insertable)]
#[table_name = "Trades"]
pub struct NewTrade{
    pub price: i64,pub seller_fee: bigdecimal::BigDecimal,pub buyer_fee: bigdecimal::BigDecimal,pub created_at: Option<NaiveDateTime>,pub updated_at: Option<NaiveDateTime>,}

错误

 #[derive(Insertable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `i64`

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)