gpt4 book ai didi

mysql - 特征 `diesel::Expression` 没有为 `f64` 实现

转载 作者:行者123 更新时间:2023-12-03 11:26:07 25 4
gpt4 key购买 nike

我正在尝试使用柴油和 mysql 建立模型。我的第一个模型编译没有问题,但是当我的第二个模型(用于向我的数据库插入新条目的模型)尝试派生 Insertable 时我收到一系列错误,指出柴油无法使用 f64 , u16 , 或 NaiveDateTime

error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
|
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `u16`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
|
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `chrono::naive::datetime::NaiveDateTime`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
|
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `f64`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&u16`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `&u16`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&chrono::naive::datetime::NaiveDateTime`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `&chrono::naive::datetime::NaiveDateTime`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&f64`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `&f64`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert u16`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `&'insert u16`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert chrono::naive::datetime::NaiveDateTime`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `&'insert chrono::naive::datetime::NaiveDateTime`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert f64`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `&'insert f64`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
这是我的 models.rs 文件
use crate::schema::*;
use serde::{Deserialize, Serialize};
use chrono::NaiveDateTime;

#[derive(Debug, Serialize, Deserialize, Queryable)]
pub struct Site {
pub site_id: i32,
pub name: String,
pub slug: String,
pub rack_size: u16,
pub date_created: chrono::NaiveDateTime,
pub latitude: f64,
pub longitude: f64
}

//#[derive(Insertable, Debug, Queryable)]
//#[table_name = "site"]
//pub struct NewSite<'a> {
// pub name: &'a str,
// pub slug: &'a str,
// pub rack_size: &'a u16,
// pub date_created: chrono::NaiveDateTime,
// pub latitude: &'a f64,
// pub longitude: &'a f64
//}
#[derive(Insertable, Debug, Queryable)]
#[table_name = "site"]
pub struct NewSite {
pub name: String,
pub slug: String,
pub rack_size: u16,
pub date_created: chrono::NaiveDateTime,
pub latitude: f64,
pub longitude: f64
}
还有我的 Cargo.toml
[package]
name = "micd"
version = "0.1.0"
authors = ["First Last <no@gmail.com>"]
edition = "2018"

[dependencies]
actix-web = "2.0.0"
actix-web-httpauth = { git = "https://github.com/actix/actix-web-httpauth" }
chrono = { version = "0.4.10", features = ["serde"] }
derive_more = "0.99.2"
diesel = { version = "1.4.2", features = ["extras", "mysql", "default"] }
dotenv = "0.15.0"
futures = "0.3.1"
r2d2 = "0.8.8"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
actix-service = "1.0.1"
alcoholic_jwt = "1.0.0"
reqwest = "0.9.22"
actix-rt = "1.0.0"
我已经尝试按照 the only SO question I could find that relates to this 的建议导入柴油中的数字特征。 .我看过的所有指南都刚刚走过这个问题,我看不出我可能做错了什么。

最佳答案

事实证明,存在哪种 sql 类型应该与哪种 rust 类型一起使用的映射,反之亦然。映射可以在这里找到:
https://docs.rs/diesel/1.4.5/diesel/deserialize/trait.FromSql.html#impl-FromSql%3CDatetime%2C%20Mysql%3E-for-MYSQL_TIME
或在这里:
https://docs.rs/diesel/1.4.5/diesel/sql_types/index.html

关于mysql - 特征 `diesel::Expression` 没有为 `f64` 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63696311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com