Skip to main content

sanitize_identifier

Function sanitize_identifier 

Source
pub fn sanitize_identifier(name: &str) -> String
Expand description

Sanitize a SQL identifier by removing non-alphanumeric/underscore characters.

Use this when quoting is not possible (e.g., PRAGMA commands, SHOW commands). This is a more restrictive approach that only allows safe characters.

Note: This function strips characters rather than erroring. If the input contains only invalid characters, the result will be an empty string.

ยงExamples

use sqlmodel_core::sanitize_identifier;

assert_eq!(sanitize_identifier("users"), "users");
assert_eq!(sanitize_identifier("user_name"), "user_name");
assert_eq!(sanitize_identifier("user\"name"), "username");
assert_eq!(sanitize_identifier("user;DROP TABLE--"), "userDROPTABLE");