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::pg::PgConnection;
|
||||||
use diesel::result::Error;
|
use diesel::result::Error;
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
|
@ -67,11 +68,14 @@ pub mod posts {
|
||||||
use crate::schema::posts::dsl::*;
|
use crate::schema::posts::dsl::*;
|
||||||
let connection = establish_connection();
|
let connection = establish_connection();
|
||||||
|
|
||||||
|
let date = Utc::now().naive_utc();
|
||||||
|
|
||||||
diesel::update(posts.filter(id.eq(updated_id)))
|
diesel::update(posts.filter(id.eq(updated_id)))
|
||||||
.set((
|
.set((
|
||||||
title.eq(&new_post.title),
|
title.eq(&new_post.title),
|
||||||
content.eq(&new_post.content),
|
content.eq(&new_post.content),
|
||||||
published.eq(&new_post.published),
|
published.eq(&new_post.published),
|
||||||
|
updated_at.eq(&date),
|
||||||
))
|
))
|
||||||
.get_result(&connection)
|
.get_result(&connection)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue