Skip to content

Commit

Permalink
Merge pull request #9 from CoLearn-Dev/base64_serializer
Browse files Browse the repository at this point in the history
Rename affected_rows and remove magic string, bump version
  • Loading branch information
nociza authored Apr 28, 2023
2 parents e794551 + 41ad527 commit 2c6654e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rdbc2"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["nociza"]
description = "Rust Database Connectivity Interface"
Expand Down
2 changes: 1 addition & 1 deletion src/dbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Row {
#[derive(Serialize, Deserialize, Debug)]
pub struct QueryResult {
pub rows: Vec<Row>,
pub affected_rows: usize,
pub affected_row_count: usize,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/dbc/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl dbc::Connection for MySQLConnection {
}
Ok(dbc::QueryResult {
rows,
affected_rows,
affected_row_count: affected_rows,
})
}
Err(err) => {
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/dbc/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand All @@ -61,7 +61,7 @@ impl dbc::Connection for SQLiteConnection {
}
Ok(dbc::QueryResult {
rows,
affected_rows: 0_usize,
affected_row_count: 0_usize,
})
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ?";
Expand All @@ -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";
Expand All @@ -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 = ?";
Expand All @@ -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 = ?";
Expand Down
2 changes: 1 addition & 1 deletion tests/mysql_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand Down

0 comments on commit 2c6654e

Please sign in to comment.