now update the "updated_at" field when modify a post

pull/1/head
kirbylife 2019-12-19 01:35:38 -06:00
parent e983cc1b9d
commit 4a305dee02
1 changed files with 4 additions and 0 deletions

View File

@ -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)
}