Skip to main content

view

Macro view 

Source
macro_rules! view {
    (
        $view_name:ident ($pk:ident) {
            $($col_name:ident -> $col_type:tt),* $(,)?
        }
    ) => { ... };
    (@resolve_column_type $type:ident) => { ... };
    (@resolve_column_type Custom($rust_type:ty, $type_name:expr)) => { ... };
    (@resolve_column_type $type_name:expr) => { ... };
    (@column_type $type:ident) => { ... };
    (@column_type Custom($rust_type:ty, $type_name:expr)) => { ... };
    (@rust_type $type:ident) => { ... };
    (@rust_type Custom($rust_type:ty, $type_name:expr)) => { ... };
    (@ddl_columns $first_col:ident -> $first_type:ident) => { ... };
    (@ddl_columns $first_col:ident -> $first_type:ident, $($rest_col:ident -> $rest_type:ident),*) => { ... };
}
Expand description

Macro for defining database views

ยงExample

use ignis_db::view;

view! {
    active_users (id) {
        id -> Int4,
        name -> Varchar,
        email -> Varchar,
    }
}

// With custom DDL:
view! {
    user_stats (id) {
        id -> Int4,
        post_count -> Int4,
        last_active -> Timestamptz,
    }
}

// Then use builder pattern for complex views:
user_stats::configure(|v| {
    v.set_ddl("CREATE VIEW user_stats AS SELECT u.id, COUNT(p.id) as post_count, MAX(p.created_at) as last_active FROM users u LEFT JOIN posts p ON u.id = p.user_id GROUP BY u.id");
    v
});