pub struct Schema {
pub tables: HashMap<String, TableSchema>,
}Expand description
Parsed schema from schema.qail file
Fields§
§tables: HashMap<String, TableSchema>Implementations§
Source§impl Schema
impl Schema
Sourcepub fn parse_file(path: &str) -> Result<Self, String>
pub fn parse_file(path: &str) -> Result<Self, String>
Parse a schema.qail file
Sourcepub fn parse(content: &str) -> Result<Self, String>
pub fn parse(content: &str) -> Result<Self, String>
Parse schema from string
Examples found in repository?
examples/typed_codegen_test.rs (line 26)
7fn main() {
8 // Test schema with protected column
9 let schema_content = r#"
10table users {
11 id UUID primary_key
12 email TEXT not_null
13 password_hash TEXT protected
14}
15
16table orders {
17 id UUID primary_key
18 user_id UUID ref:users.id
19 status TEXT
20}
21"#;
22
23 println!("=== QAIL Typed Codegen Integration Test ===\n");
24
25 // Parse schema
26 let schema = Schema::parse(schema_content).expect("Failed to parse schema");
27 println!("✓ Parsed schema with {} tables", schema.tables.len());
28
29 // Generate code
30 let code = generate_schema_code(&schema);
31 println!("✓ Generated {} bytes of Rust code\n", code.len());
32
33 // Show generated code
34 println!("=== Generated Code ===\n");
35 println!("{}", code);
36
37 // Verify key features
38 println!("\n=== Verification ===\n");
39
40 // 1. TypedColumn with Policy
41 assert!(code.contains("TypedColumn<String, Public>"), "Missing Public column");
42 println!("✓ TypedColumn<T, Public> generated");
43
44 assert!(code.contains("TypedColumn<String, Protected>"), "Missing Protected column");
45 println!("✓ TypedColumn<T, Protected> generated for password_hash");
46
47 // 2. RelatedTo impls
48 assert!(code.contains("impl RelatedTo<users::Users> for orders::Orders"), "Missing FK relation");
49 println!("✓ RelatedTo<users::Users> for orders::Orders generated");
50
51 assert!(code.contains("impl RelatedTo<orders::Orders> for users::Users"), "Missing reverse relation");
52 println!("✓ RelatedTo<orders::Orders> for users::Users generated (reverse)");
53
54 println!("\n✅ All typed codegen tests passed!");
55}Sourcepub fn table(&self, name: &str) -> Option<&TableSchema>
pub fn table(&self, name: &str) -> Option<&TableSchema>
Get table schema
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more