From 439b788641f3ad56eb9e90d410f0949babc2176f Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 15 Oct 2020 06:18:44 +0500 Subject: [PATCH] Debug queries --- src/models.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/models.rs b/src/models.rs index a072c30..476f5bc 100644 --- a/src/models.rs +++ b/src/models.rs @@ -3,6 +3,7 @@ use crate::database::DbConn; use crate::schema::users; use diesel::prelude::*; +use diesel::query_builder::AsQuery; #[derive(Debug, Serialize, Queryable)] pub struct User { @@ -20,7 +21,13 @@ pub struct NewUser<'a> { impl User { pub fn all(db_conn: DbConn) -> Result, ()> { - let result = users::table.load::(&*db_conn); + let query = users::table.as_query(); + + let debug = diesel::debug_query::(&query); + + println!("{}", debug); + + let result = query.load::(&*db_conn); match result { Err(_) => Err(()), @@ -31,9 +38,13 @@ impl User { impl<'a> NewUser<'a> { pub fn save(&self, db_conn: DbConn) -> Result<(), ()> { - let result = diesel::insert_into(users::table) - .values(self) - .get_result::(&*db_conn); + let query = diesel::insert_into(users::table).values(self); + + let debug = diesel::debug_query::(&query); + + println!("{}", debug); + + let result = query.get_result::(&*db_conn); match result { Err(_) => Err(()),