Skip to content

Commit

Permalink
fix: update entry on conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Mar 6, 2024
1 parent 3098f9e commit a481753
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pragma-entities/src/models/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::models::DieselResult;
use crate::schema::entries;
use bigdecimal::BigDecimal;
use diesel::internal::derives::multiconnection::chrono::NaiveDateTime;
use diesel::query_builder::AsChangeset;
use diesel::upsert::*;
use diesel::{
ExpressionMethods, Insertable, PgConnection, PgTextExpressionMethods, QueryDsl, Queryable,
RunQueryDsl, Selectable, SelectableHelper,
Expand All @@ -22,7 +24,7 @@ pub struct Entry {
pub price: BigDecimal,
}

#[derive(Serialize, Deserialize, Insertable)]
#[derive(Serialize, Deserialize, Insertable, AsChangeset)]
#[diesel(table_name = entries)]
pub struct NewEntry {
pub pair_id: String,
Expand All @@ -44,6 +46,9 @@ impl Entry {
diesel::insert_into(entries::table)
.values(data)
.returning(Entry::as_returning())
.on_conflict((entries::pair_id, entries::source, entries::timestamp))
.do_update()
.set(data)
.get_results(conn)
}

Expand Down

0 comments on commit a481753

Please sign in to comment.