Я пытаюсь создать структуру, которую я могу использовать в дизеле для вставки. В частности, я делаю структуру Insertable. При компиляции я получаю эту ошибку.
У меня есть структура, которую я пытаюсь создать Insertable
через атрибут производного. У меня есть поле с именем Bounty
, которое должно представлять деньги, поэтому я использую BigDecimal
в качестве типа. После компиляции я получаю ошибку в заголовке. Я также пытался использовать f64
, но это выдает ту же ошибку.
#[macro_use]
extern crate diesel;
extern crate bigdecimal;
mod schema {
use bigdecimal::BigDecimal;
table! {
Threads (Id) {
Id -> Int8,
Views -> Int4,
Points -> Int4,
FlagPoints -> Int4,
IsDisabled -> Bool,
IsAnswered -> Bool,
Bounty -> Numeric,
Title -> Varchar,
Body -> Text,
UserId -> Int8,
CreatedBy -> Varchar,
CreatedOn -> Timestamptz,
LastModifiedBy -> Varchar,
LastModifiedOn -> Timestamptz,
}
}
#[allow(non_snake_case)]
#[derive(Debug, Insertable)]
#[table_name = "Threads"]
pub struct InsertableThread {
pub Bounty: BigDecimal,
pub Title: String,
pub Body: String,
pub UserId: i64
}
}
fn main() {}
У меня есть структура внутри собственного файла, и это весь код. Структура Thread
компилируется без проблем. Ошибка происходит на InsertableThread
, поскольку она использует BigDecimal
. Это ошибка, которая в результате.
error[E0277]: the trait bound `bigdecimal::BigDecimal: diesel::Expression` is not satisfied
--> src/main.rs:29:21
|
29 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `bigdecimal::BigDecimal`
|
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Numeric>` for `bigdecimal::BigDecimal`
error[E0277]: the trait bound `bigdecimal::BigDecimal: diesel::Expression` is not satisfied
--> src/main.rs:29:21
|
29 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `bigdecimal::BigDecimal`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&bigdecimal::BigDecimal`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Numeric>` for `&bigdecimal::BigDecimal`
error[E0277]: the trait bound `bigdecimal::BigDecimal: diesel::Expression` is not satisfied
--> src/main.rs:29:21
|
29 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `bigdecimal::BigDecimal`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert bigdecimal::BigDecimal`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Numeric>` for `&'insert bigdecimal::BigDecimal`
Я использую Rust 1.34, дизель 1.4.2 и Postgres 11.
Я готов изменить типы в базе данных, Postgres или в коде Rust. База данных использует numeric
, а в коде Rust я пробовал f64
и BigDecimal
. Я также готов реализовать эту черту непосредственно, но мне нужно несколько советов о том, как это сделать, поскольку я не смог найти образцы.