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

feat(core): Add support for Table names in column checks #165

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
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"));
}
}
Loading