anda_db_schema/
lib.rs

1mod document;
2mod error;
3mod field;
4mod resource;
5mod schema;
6mod value_serde;
7
8pub use anda_db_derive::{AndaDBSchema, FieldTyped};
9
10pub use document::*;
11pub use error::*;
12pub use field::*;
13pub use resource::*;
14pub use schema::*;
15
16/// Validate a field name
17///
18/// Field names must:
19/// - Not be empty
20/// - Not exceed 64 characters
21/// - Contain only lowercase letters, numbers, and underscores
22///
23/// # Arguments
24/// * `s` - The field name to validate
25///
26/// # Returns
27/// * `Result<(), SchemaError>` - Ok if valid, or an error message if invalid
28pub fn validate_field_name(s: &str) -> Result<(), SchemaError> {
29    if s.is_empty() {
30        return Err(SchemaError::FieldName("empty string".to_string()));
31    }
32
33    if s.len() > 64 {
34        return Err(SchemaError::FieldName(format!(
35            "string length {} exceeds the limit 64",
36            s.len()
37        )));
38    }
39
40    for c in s.chars() {
41        if !matches!(c, 'a'..='z' | '0'..='9' | '_' ) {
42            return Err(SchemaError::FieldName(format!(
43                "Invalid character {c:?} in {s:?}"
44            )));
45        }
46    }
47    Ok(())
48}