1
0
Fork 0

Debug queries

This commit is contained in:
Alex Kotov 2020-10-15 06:18:44 +05:00
parent 94320a15e9
commit 439b788641
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -3,6 +3,7 @@ use crate::database::DbConn;
use crate::schema::users; use crate::schema::users;
use diesel::prelude::*; use diesel::prelude::*;
use diesel::query_builder::AsQuery;
#[derive(Debug, Serialize, Queryable)] #[derive(Debug, Serialize, Queryable)]
pub struct User { pub struct User {
@ -20,7 +21,13 @@ pub struct NewUser<'a> {
impl User { impl User {
pub fn all(db_conn: DbConn) -> Result<Vec<User>, ()> { pub fn all(db_conn: DbConn) -> Result<Vec<User>, ()> {
let result = users::table.load::<User>(&*db_conn); let query = users::table.as_query();
let debug = diesel::debug_query::<diesel::pg::Pg, _>(&query);
println!("{}", debug);
let result = query.load::<User>(&*db_conn);
match result { match result {
Err(_) => Err(()), Err(_) => Err(()),
@ -31,9 +38,13 @@ impl User {
impl<'a> NewUser<'a> { impl<'a> NewUser<'a> {
pub fn save(&self, db_conn: DbConn) -> Result<(), ()> { pub fn save(&self, db_conn: DbConn) -> Result<(), ()> {
let result = diesel::insert_into(users::table) let query = diesel::insert_into(users::table).values(self);
.values(self)
.get_result::<User>(&*db_conn); let debug = diesel::debug_query::<diesel::pg::Pg, _>(&query);
println!("{}", debug);
let result = query.get_result::<User>(&*db_conn);
match result { match result {
Err(_) => Err(()), Err(_) => Err(()),