I'm trying to use rust_decimal with sqlx for money postgresql type and got error.
Of course i use decimal feature for sqlx.
There is full example
Table
create table inventory (
id bigserial not null,
name text not null,
price money not null,
constraint inventory_pk primary key (id)
);
Structure
pub struct Item {
pub id: i64,
pub name: String,
pub price: Decimal,
}
Query
let si = sqlx::query_as!(
Item,
r#"
insert into inventory(name, price)
values ($1, $2)
returning id, name, price
"#,
i.name,
i.price
)
.fetch_one(pool)
.await?;
Error
error[E0308]: mismatched types
--> src/main.rs:38:14
|
| let si = sqlx::query_as!(
| ______________^
| | Item,
| | r#"
| | insert into inventory(name, price)
|
| | i.price
| | )
| |_____^ expected struct `Decimal`, found struct `PgMoney`
What i'm doing wrong?