From bde71077c692b51970ec559ab66597715c5230be Mon Sep 17 00:00:00 2001 From: Chase Willden Date: Fri, 15 Nov 2024 22:23:09 -0700 Subject: [PATCH] Switch printlns to log crate statements --- njord/src/mssql/delete.rs | 1 - njord/src/mssql/insert.rs | 6 +++--- njord/src/mssql/select.rs | 1 - njord/src/mssql/update.rs | 1 - njord/src/mysql/delete.rs | 1 - njord/src/mysql/insert.rs | 6 +++--- njord/src/mysql/select.rs | 1 - njord/src/mysql/update.rs | 6 +----- njord/src/oracle/delete.rs | 1 - njord/src/oracle/insert.rs | 8 ++++---- njord/src/oracle/mod.rs | 2 +- njord/src/oracle/select.rs | 3 --- njord/src/oracle/update.rs | 1 - njord/src/sqlite/delete.rs | 1 - njord/src/sqlite/insert.rs | 11 ++++------- njord/src/sqlite/select.rs | 1 - njord/src/sqlite/update.rs | 1 - 17 files changed, 16 insertions(+), 36 deletions(-) diff --git a/njord/src/mssql/delete.rs b/njord/src/mssql/delete.rs index b7fc987c..b5cff487 100644 --- a/njord/src/mssql/delete.rs +++ b/njord/src/mssql/delete.rs @@ -114,7 +114,6 @@ impl<'a, T: Table + Default> DeleteQueryBuilder<'a, T> { let query = format!("DELETE FROM {} {}", table_name_str, where_condition_str,); info!("{}", query); - println!("{}", query); // Execute SQL match self.conn.client.execute(&query, &[]).await { diff --git a/njord/src/mssql/insert.rs b/njord/src/mssql/insert.rs index 4f710a2f..58e89f56 100644 --- a/njord/src/mssql/insert.rs +++ b/njord/src/mssql/insert.rs @@ -31,7 +31,7 @@ use crate::{mssql::MSSQLError, query::QueryBuilder, table::Table}; -use log::info; +use log::{debug, info}; use std::fmt::Error; use super::Connection; @@ -67,7 +67,7 @@ pub async fn insert( let joined_statements = statements.join(", "); - println!("{}", joined_statements); + debug!("{}", joined_statements); match conn.client.query(&joined_statements, &[]).await { Ok(_) => return Ok("Inserted into table, done.".to_string()), @@ -162,7 +162,7 @@ fn generate_statement(table_row: &T, first_statement: bool) -> Result< for (column_name, value) in column_fields.iter().zip(column_values.iter()) { // Check if the field is an AutoIncrementPrimaryKey if table_row.is_auto_increment_primary_key(value) { - println!("Skipping AutoIncrementPrimaryKey field in SQL statement generation."); + debug!("Skipping AutoIncrementPrimaryKey field in SQL statement generation."); continue; } columns_str.push_str(&format!("{}, ", column_name)); diff --git a/njord/src/mssql/select.rs b/njord/src/mssql/select.rs index 7ac21628..2b0f7a10 100644 --- a/njord/src/mssql/select.rs +++ b/njord/src/mssql/select.rs @@ -333,7 +333,6 @@ impl<'a, T: Table + Default> SelectQueryBuilder<'a, T> { let final_query = self.build_query(); info!("{}", final_query); - println!("{}", final_query); let mut stream = conn.client.query(final_query, &[]).await?; diff --git a/njord/src/mssql/update.rs b/njord/src/mssql/update.rs index d66cfacb..69288655 100644 --- a/njord/src/mssql/update.rs +++ b/njord/src/mssql/update.rs @@ -171,7 +171,6 @@ impl<'a, T: Table + Default> UpdateQueryBuilder<'a, T> { ); info!("{}", query); - println!("{}", query); // Prepare SQL statement match self.conn.client.execute(query.as_str(), &[]).await { diff --git a/njord/src/mysql/delete.rs b/njord/src/mysql/delete.rs index f31d5d8d..5ae1fc3d 100644 --- a/njord/src/mysql/delete.rs +++ b/njord/src/mysql/delete.rs @@ -163,7 +163,6 @@ impl<'a, T: Table + Default> DeleteQueryBuilder<'a, T> { ); info!("{}", query); - println!("{}", query); // Execute SQL let _ = self.conn.query_drop(&query.to_string()); diff --git a/njord/src/mysql/insert.rs b/njord/src/mysql/insert.rs index 58b9046e..3d08a0a5 100644 --- a/njord/src/mysql/insert.rs +++ b/njord/src/mysql/insert.rs @@ -34,7 +34,7 @@ use crate::{query::QueryBuilder, table::Table}; use mysql::{prelude::Queryable, PooledConn}; use rusqlite::Error as RusqliteError; -use log::info; +use log::{debug, info}; use std::fmt::Error; /// Inserts rows into a MySql table. @@ -164,7 +164,7 @@ fn generate_statement(table_row: &T, first_statement: bool) -> Result< for (column_name, value) in column_fields.iter().zip(column_values.iter()) { // Check if the field is an AutoIncrementPrimaryKey if table_row.is_auto_increment_primary_key(value) { - println!("Skipping AutoIncrementPrimaryKey field in SQL statement generation."); + debug!("Skipping AutoIncrementPrimaryKey field in SQL statement generation."); continue; } columns_str.push_str(&format!("{}, ", column_name)); @@ -193,7 +193,7 @@ fn generate_statement(table_row: &T, first_statement: bool) -> Result< format!("({})", values_str) }; - println!("{}", sql); // For debugging purposes + debug!("{}", sql); // For debugging purposes Ok(sql) } diff --git a/njord/src/mysql/select.rs b/njord/src/mysql/select.rs index dcd85f44..b403565a 100644 --- a/njord/src/mysql/select.rs +++ b/njord/src/mysql/select.rs @@ -359,7 +359,6 @@ impl<'a, T: Table + Default> SelectQueryBuilder<'a, T> { let final_query = self.build_query(); info!("{}", final_query); - println!("{}", final_query); let query_set = conn.query_iter(final_query.as_str()).unwrap(); diff --git a/njord/src/mysql/update.rs b/njord/src/mysql/update.rs index 8c47ed54..c8413b4b 100644 --- a/njord/src/mysql/update.rs +++ b/njord/src/mysql/update.rs @@ -56,10 +56,7 @@ use super::select::SelectQueryBuilder; /// # Returns /// /// An `UpdateQueryBuilder` instance. -pub fn update( - conn: &mut PooledConn, - table: T, -) -> UpdateQueryBuilder { +pub fn update(conn: &mut PooledConn, table: T) -> UpdateQueryBuilder { UpdateQueryBuilder::new(conn, table) } @@ -221,7 +218,6 @@ impl<'a, T: Table + Default> UpdateQueryBuilder<'a, T> { ); info!("{}", query); - println!("{}", query); // Prepare SQL statement let _ = self.conn.query_drop(query.as_str()); diff --git a/njord/src/oracle/delete.rs b/njord/src/oracle/delete.rs index bc139df2..caa05f94 100644 --- a/njord/src/oracle/delete.rs +++ b/njord/src/oracle/delete.rs @@ -163,7 +163,6 @@ impl<'a, T: Table + Default> DeleteQueryBuilder<'a, T> { ); info!("{}", query); - println!("{}", query); // Execute SQL let _ = self.conn.execute(&query, &[]); diff --git a/njord/src/oracle/insert.rs b/njord/src/oracle/insert.rs index a0c3674f..67dabe94 100644 --- a/njord/src/oracle/insert.rs +++ b/njord/src/oracle/insert.rs @@ -34,7 +34,7 @@ use crate::{query::QueryBuilder, table::Table}; use oracle::Connection; use rusqlite::Error as RusqliteError; -use log::info; +use log::{debug, info}; use std::fmt::Error; /// Inserts rows into a Oracle table. @@ -68,7 +68,7 @@ pub fn insert( let joined_statements = statements.join(", "); - println!("{}", joined_statements); + debug!("{}", joined_statements); let _ = match conn.execute(&joined_statements, &[]) { Ok(_) => info!("Inserted into table, done."), @@ -167,7 +167,7 @@ fn generate_statement(table_row: &T, first_statement: bool) -> Result< for (column_name, value) in column_fields.iter().zip(column_values.iter()) { // Check if the field is an AutoIncrementPrimaryKey if table_row.is_auto_increment_primary_key(value) { - println!("Skipping AutoIncrementPrimaryKey field in SQL statement generation."); + debug!("Skipping AutoIncrementPrimaryKey field in SQL statement generation."); continue; } columns_str.push_str(&format!("{}, ", column_name)); @@ -196,7 +196,7 @@ fn generate_statement(table_row: &T, first_statement: bool) -> Result< format!("({})", values_str) }; - println!("{}", sql); // For debugging purposes + debug!("{}", sql); // For debugging purposes Ok(sql) } diff --git a/njord/src/oracle/mod.rs b/njord/src/oracle/mod.rs index 470fc31e..a93ca3a6 100644 --- a/njord/src/oracle/mod.rs +++ b/njord/src/oracle/mod.rs @@ -67,7 +67,7 @@ pub fn open(username: &str, password: &str, connect_string: &str) -> Result { - println!("Error: {}", err); + eprintln!("Error: {}", err); return Err(err); } diff --git a/njord/src/oracle/select.rs b/njord/src/oracle/select.rs index 1859d0d4..b9011a1c 100644 --- a/njord/src/oracle/select.rs +++ b/njord/src/oracle/select.rs @@ -331,7 +331,6 @@ impl<'a, T: Table + Default> SelectQueryBuilder<'a, T> { let final_query = self.build_query(); info!("{}", final_query); - println!("{}", final_query); let mut stmt = conn.statement(&final_query).build()?; let rows = stmt.query(&[])?; @@ -359,8 +358,6 @@ impl<'a, T: Table + Default> SelectQueryBuilder<'a, T> { } results.push(instance); - - println!(); } Ok(results) diff --git a/njord/src/oracle/update.rs b/njord/src/oracle/update.rs index 484f76b0..e576db10 100644 --- a/njord/src/oracle/update.rs +++ b/njord/src/oracle/update.rs @@ -218,7 +218,6 @@ impl<'a, T: Table + Default> UpdateQueryBuilder<'a, T> { ); info!("{}", query); - println!("{}", query); // Prepare SQL statement let _ = self.conn.execute(query.as_str(), &[]); diff --git a/njord/src/sqlite/delete.rs b/njord/src/sqlite/delete.rs index 47e16c89..3f7a4f80 100644 --- a/njord/src/sqlite/delete.rs +++ b/njord/src/sqlite/delete.rs @@ -162,7 +162,6 @@ impl<'a, T: Table + Default> DeleteQueryBuilder<'a, T> { ); info!("{}", query); - println!("{}", query); // Execute SQL let _ = self.conn.execute(&query.to_string(), []); diff --git a/njord/src/sqlite/insert.rs b/njord/src/sqlite/insert.rs index 5239a2b7..a2158a21 100644 --- a/njord/src/sqlite/insert.rs +++ b/njord/src/sqlite/insert.rs @@ -33,7 +33,7 @@ use crate::{query::QueryBuilder, table::Table}; use rusqlite::Error as RusqliteError; -use log::info; +use log::{debug, info}; use rusqlite::{Connection, Result}; use std::fmt::Error; @@ -54,10 +54,7 @@ use std::fmt::Error; /// /// A `Result` containing a `String` representing the joined SQL statements /// if the insertion is successful, or a `RusqliteError` if an error occurs. -pub fn insert( - conn: &Connection, - table_rows: Vec, -) -> Result { +pub fn insert(conn: &Connection, table_rows: Vec) -> Result { let mut statements: Vec = Vec::new(); for (index, table_row) in table_rows.iter().enumerate() { match generate_statement(table_row, index == 0) { @@ -161,7 +158,7 @@ fn generate_statement(table_row: &T, first_statement: bool) -> Result< for (column_name, value) in column_fields.iter().zip(column_values.iter()) { // Check if the field is an AutoIncrementPrimaryKey if table_row.is_auto_increment_primary_key(value) { - println!("Skipping AutoIncrementPrimaryKey field in SQL statement generation."); + debug!("Skipping AutoIncrementPrimaryKey field in SQL statement generation."); continue; } columns_str.push_str(&format!("{}, ", column_name)); @@ -190,7 +187,7 @@ fn generate_statement(table_row: &T, first_statement: bool) -> Result< format!("({})", values_str) }; - println!("{}", sql); // For debugging purposes + debug!("{}", sql); // For debugging purposes Ok(sql) } diff --git a/njord/src/sqlite/select.rs b/njord/src/sqlite/select.rs index 4d8aacc2..496434eb 100644 --- a/njord/src/sqlite/select.rs +++ b/njord/src/sqlite/select.rs @@ -362,7 +362,6 @@ impl<'a, T: Table + Default> SelectQueryBuilder<'a, T> { let final_query = self.build_query(); info!("{}", final_query); - println!("{}", final_query); // Prepare SQL statement let mut stmt = self.conn.prepare(final_query.as_str())?; diff --git a/njord/src/sqlite/update.rs b/njord/src/sqlite/update.rs index d8c39b3f..a818ef98 100644 --- a/njord/src/sqlite/update.rs +++ b/njord/src/sqlite/update.rs @@ -217,7 +217,6 @@ impl<'a, T: Table + Default> UpdateQueryBuilder<'a, T> { ); info!("{}", query); - println!("{}", query); // Prepare SQL statement match self.conn.prepare(query.as_str()) {