From 41ad5274c38be019b419404b62e2bad6dd93f261 Mon Sep 17 00:00:00 2001 From: nociza Date: Fri, 28 Apr 2023 15:15:20 -0700 Subject: [PATCH] Rename affected_rows and remove magic string, bump version --- Cargo.toml | 2 +- src/dbc.rs | 2 +- src/dbc/mysql.rs | 4 ++-- src/dbc/sqlite.rs | 4 ++-- tests/common.rs | 14 +++++++------- tests/mysql_test.rs | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 357cc48..3df562b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rdbc2" -version = "0.2.0" +version = "0.2.1" edition = "2021" authors = ["nociza"] description = "Rust Database Connectivity Interface" diff --git a/src/dbc.rs b/src/dbc.rs index bcc76dc..c55d0ec 100644 --- a/src/dbc.rs +++ b/src/dbc.rs @@ -108,7 +108,7 @@ impl Row { #[derive(Serialize, Deserialize, Debug)] pub struct QueryResult { pub rows: Vec, - pub affected_rows: usize, + pub affected_row_count: usize, } #[derive(Serialize, Deserialize, Clone, Debug)] diff --git a/src/dbc/mysql.rs b/src/dbc/mysql.rs index 60aa0c0..5ebda09 100644 --- a/src/dbc/mysql.rs +++ b/src/dbc/mysql.rs @@ -58,7 +58,7 @@ impl dbc::Connection for MySQLConnection { } Ok(dbc::QueryResult { rows, - affected_rows, + affected_row_count: affected_rows, }) } Err(err) => { @@ -99,7 +99,7 @@ impl dbc::Connection for MySQLConnection { } return Ok(dbc::QueryResult { rows, - affected_rows, + affected_row_count: affected_rows, }); } Err(dbc::Error::from(err)) diff --git a/src/dbc/sqlite.rs b/src/dbc/sqlite.rs index 06eccb9..f97d720 100644 --- a/src/dbc/sqlite.rs +++ b/src/dbc/sqlite.rs @@ -41,7 +41,7 @@ impl dbc::Connection for SQLiteConnection { let affected_rows = statement.execute([])?; return Ok(dbc::QueryResult { rows: Vec::new(), - affected_rows, + affected_row_count: affected_rows, }); } @@ -61,7 +61,7 @@ impl dbc::Connection for SQLiteConnection { } Ok(dbc::QueryResult { rows, - affected_rows: 0_usize, + affected_row_count: 0_usize, }) } } diff --git a/tests/common.rs b/tests/common.rs index e37912a..45743b5 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -32,7 +32,7 @@ pub(crate) async fn test_simple_query(mut database: dbc::Database) -> Result<(), // Update the name of the first row to "updated" let update_query = "UPDATE test_table SET name = ? WHERE id = ?"; let result = database.execute_query_with_params(update_query, &["updated", "1"])?; - assert_eq!(result.affected_rows, 1); + assert_eq!(result.affected_row_count, 1); // Select the first row from test_table where the name is "updated" let select_query = "SELECT * FROM test_table WHERE name = ?"; @@ -55,9 +55,9 @@ pub(crate) async fn test_query_with_params(mut database: dbc::Database) -> Resul // Insert two rows into test_table let insert_query = "INSERT INTO test_table (name) VALUES (?)"; let result = database.execute_query_with_params(insert_query, &["test1"])?; - assert_eq!(result.affected_rows, 1); + assert_eq!(result.affected_row_count, 1); let result = database.execute_query_with_params(insert_query, &["test2"])?; - assert_eq!(result.affected_rows, 1); + assert_eq!(result.affected_row_count, 1); // Select all rows from test_table let select_query = "SELECT * FROM test_table"; @@ -79,7 +79,7 @@ pub(crate) async fn test_query_with_params(mut database: dbc::Database) -> Resul // Update the name of the first row to "updated" let update_query = "UPDATE test_table SET name = ? WHERE id = ?"; let result = database.execute_query_with_params(update_query, &["updated", "1"])?; - assert_eq!(result.affected_rows, 1); + assert_eq!(result.affected_row_count, 1); // Select the first row from test_table where the name is "updated" let select_query = "SELECT * FROM test_table WHERE name = ?"; @@ -104,14 +104,14 @@ pub(crate) async fn test_query_with_params_and_serialize( // Insert two rows into test_table let insert_query = "INSERT INTO test_table (name) VALUES (?)"; let result = database.execute_query_with_params(insert_query, &["test1"])?; - assert_eq!(result.affected_rows, 1); + assert_eq!(result.affected_row_count, 1); let result = database.execute_query_with_params(insert_query, &["test2"])?; - assert_eq!(result.affected_rows, 1); + assert_eq!(result.affected_row_count, 1); // Update the name of the first row to "updated" let update_query = "UPDATE test_table SET name = ? WHERE id = ?"; let result = database.execute_query_with_params(update_query, &["updated", "1"])?; - assert_eq!(result.affected_rows, 1); + assert_eq!(result.affected_row_count, 1); // Select the first row from test_table where the name is "updated" let select_query = "SELECT * FROM test_table WHERE id = ?"; diff --git a/tests/mysql_test.rs b/tests/mysql_test.rs index fe5b496..4bb2c08 100644 --- a/tests/mysql_test.rs +++ b/tests/mysql_test.rs @@ -8,7 +8,7 @@ fn _get_mysql_connection_url() -> String { if std::env::var("MYSQL_DATABASE_URL").is_ok() { std::env::var("MYSQL_DATABASE_URL").unwrap() } else { - "mysql://localhost:3306/?user=nociza&password=password".to_owned() + panic!("Please set the environment variable MYSQL_DATABASE_URL to a valid MySQL connection string."); } }