Skip to main content

Schema

Struct Schema 

Source
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

Source

pub fn parse_file(path: &str) -> Result<Self, String>

Parse a schema.qail file

Source

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}
Source

pub fn has_table(&self, name: &str) -> bool

Check if table exists

Source

pub fn table(&self, name: &str) -> Option<&TableSchema>

Get table schema

Source

pub fn merge_migrations( &mut self, migrations_dir: &str, ) -> Result<usize, String>

Merge pending migrations into the schema Scans migration directory for .sql files and extracts:

  • CREATE TABLE statements
  • ALTER TABLE ADD COLUMN statements

Trait Implementations§

Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Schema

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ColumnValue<Value> for T