Skip to content

Commit

Permalink
feat(core): Add support for Table names in column checks
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekMasher committed Jan 9, 2025
1 parent 72502dc commit 5df82bd
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion geekorm-core/src/builder/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ pub struct Table {
impl Table {
/// Function to check if a column name is valid
pub fn is_valid_column(&self, column: &str) -> bool {
self.columns.is_valid_column(column)
if let Some((table, column)) = column.split_once('.') {
if table != self.name {
return false;
}
self.columns.is_valid_column(column)
} else {
self.columns.is_valid_column(column)
}
}

/// Get the name of the primary key column
Expand Down Expand Up @@ -365,4 +372,16 @@ mod tests {

assert_eq!(delete_query, "DELETE FROM Test WHERE id = ?;");
}

#[test]
fn test_is_valid_column() {
let table = table();

assert!(table.is_valid_column("id"));
assert!(table.is_valid_column("name"));
assert!(!table.is_valid_column("name2"));
// Test with table name
assert!(table.is_valid_column("Test.name"));
assert!(!table.is_valid_column("Tests.name"));
}
}

0 comments on commit 5df82bd

Please sign in to comment.