now update the "updated_at" field when modify a post
parent
e983cc1b9d
commit
4a305dee02
|
@ -1,3 +1,4 @@
|
|||
use chrono::prelude::Utc;
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::result::Error;
|
||||
use diesel::Connection;
|
||||
|
@ -67,11 +68,14 @@ pub mod posts {
|
|||
use crate::schema::posts::dsl::*;
|
||||
let connection = establish_connection();
|
||||
|
||||
let date = Utc::now().naive_utc();
|
||||
|
||||
diesel::update(posts.filter(id.eq(updated_id)))
|
||||
.set((
|
||||
title.eq(&new_post.title),
|
||||
content.eq(&new_post.content),
|
||||
published.eq(&new_post.published),
|
||||
updated_at.eq(&date),
|
||||
))
|
||||
.get_result(&connection)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue