Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch printlns to log crate statements #197

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion njord/src/mssql/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions njord/src/mssql/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +67,7 @@ pub async fn insert<T: Table>(

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()),
Expand Down Expand Up @@ -162,7 +162,7 @@ fn generate_statement<T: Table>(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));
Expand Down
1 change: 0 additions & 1 deletion njord/src/mssql/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
1 change: 0 additions & 1 deletion njord/src/mssql/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion njord/src/mysql/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions njord/src/mysql/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -164,7 +164,7 @@ fn generate_statement<T: Table>(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));
Expand Down Expand Up @@ -193,7 +193,7 @@ fn generate_statement<T: Table>(table_row: &T, first_statement: bool) -> Result<
format!("({})", values_str)
};

println!("{}", sql); // For debugging purposes
debug!("{}", sql); // For debugging purposes

Ok(sql)
}
1 change: 0 additions & 1 deletion njord/src/mysql/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 1 addition & 5 deletions njord/src/mysql/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ use super::select::SelectQueryBuilder;
/// # Returns
///
/// An `UpdateQueryBuilder` instance.
pub fn update<T: Table + Default>(
conn: &mut PooledConn,
table: T,
) -> UpdateQueryBuilder<T> {
pub fn update<T: Table + Default>(conn: &mut PooledConn, table: T) -> UpdateQueryBuilder<T> {
UpdateQueryBuilder::new(conn, table)
}

Expand Down Expand Up @@ -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());
Expand Down
1 change: 0 additions & 1 deletion njord/src/oracle/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ impl<'a, T: Table + Default> DeleteQueryBuilder<'a, T> {
);

info!("{}", query);
println!("{}", query);

// Execute SQL
let _ = self.conn.execute(&query, &[]);
Expand Down
8 changes: 4 additions & 4 deletions njord/src/oracle/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn insert<T: Table>(

let joined_statements = statements.join(", ");

println!("{}", joined_statements);
debug!("{}", joined_statements);

let _ = match conn.execute(&joined_statements, &[]) {
Ok(_) => info!("Inserted into table, done."),
Expand Down Expand Up @@ -167,7 +167,7 @@ fn generate_statement<T: Table>(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));
Expand Down Expand Up @@ -196,7 +196,7 @@ fn generate_statement<T: Table>(table_row: &T, first_statement: bool) -> Result<
format!("({})", values_str)
};

println!("{}", sql); // For debugging purposes
debug!("{}", sql); // For debugging purposes

Ok(sql)
}
2 changes: 1 addition & 1 deletion njord/src/oracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn open(username: &str, password: &str, connect_string: &str) -> Result<Conn
return Ok(conn);
}
Err(err) => {
println!("Error: {}", err);
eprintln!("Error: {}", err);

return Err(err);
}
Expand Down
3 changes: 0 additions & 3 deletions njord/src/oracle/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&[])?;
Expand Down Expand Up @@ -359,8 +358,6 @@ impl<'a, T: Table + Default> SelectQueryBuilder<'a, T> {
}

results.push(instance);

println!();
}

Ok(results)
Expand Down
1 change: 0 additions & 1 deletion njord/src/oracle/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(), &[]);
Expand Down
1 change: 0 additions & 1 deletion njord/src/sqlite/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(), []);
Expand Down
11 changes: 4 additions & 7 deletions njord/src/sqlite/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<T: Table>(
conn: &Connection,
table_rows: Vec<T>,
) -> Result<String, RusqliteError> {
pub fn insert<T: Table>(conn: &Connection, table_rows: Vec<T>) -> Result<String, RusqliteError> {
let mut statements: Vec<String> = Vec::new();
for (index, table_row) in table_rows.iter().enumerate() {
match generate_statement(table_row, index == 0) {
Expand Down Expand Up @@ -161,7 +158,7 @@ fn generate_statement<T: Table>(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));
Expand Down Expand Up @@ -190,7 +187,7 @@ fn generate_statement<T: Table>(table_row: &T, first_statement: bool) -> Result<
format!("({})", values_str)
};

println!("{}", sql); // For debugging purposes
debug!("{}", sql); // For debugging purposes

Ok(sql)
}
1 change: 0 additions & 1 deletion njord/src/sqlite/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down
1 change: 0 additions & 1 deletion njord/src/sqlite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Loading