initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
use self::modelos::Post;
|
||||
use rust_diesel_blogs::*;
|
||||
use diesel::{prelude::*, connection};
|
||||
use std::env::args;
|
||||
|
||||
fn main() {
|
||||
use self::schema::posts::dsl::{posts, published};
|
||||
|
||||
let id = args()
|
||||
.nth(1)
|
||||
.expect("publicar requiere un id")
|
||||
.parse::<i32>()
|
||||
.expect("ID invalida");
|
||||
|
||||
let connection = &mut establecer_coneccion();
|
||||
|
||||
let post = diesel::update(posts.find(id))
|
||||
.set(published.eq(true))
|
||||
.returning(Post::as_returning())
|
||||
.get_results(connection)
|
||||
.unwrap();
|
||||
println!("Publicado post {}", post.get(0).unwrap().title);
|
||||
}
|
||||
Reference in New Issue
Block a user