use remdb_macros::MemdbTable;
#[derive(MemdbTable)]
#[memdb_schema(
ddl = "CREATE TABLE user (id BIGINT PRIMARY KEY, name TEXT NOT NULL, age BIGINT, active BOOLEAN);
CREATE INDEX idx_user_name ON user USING btree (name);
CREATE INDEX idx_user_age ON user USING hash (age);
CREATE INDEX idx_user_active ON user USING sortedarray (active);
CREATE TABLE product (id BIGINT PRIMARY KEY, name TEXT NOT NULL, price REAL NOT NULL, category TEXT);
CREATE INDEX idx_product_price ON product USING ttree (price);
CREATE INDEX idx_product_category ON product (category); -- 默认BTree"
)]
struct Database;
fn main() {
println!("=== remdb DDL Index Example ===");
println!("\n1. Testing User struct:");
let user = User {
id: 1,
name: "Alice".to_string(),
age: Some(30),
active: Some(true),
};
println!(" Generated User struct: {:?}", user);
println!(" User name: {}", user.name);
println!(" User age: {:?}", user.age);
println!("\n2. Testing Product struct:");
let product = Product {
id: 1,
name: "Laptop".to_string(),
price: 999.99,
category: Some("Electronics".to_string()),
};
println!(" Generated Product struct: {:?}", product);
println!(" Product name: {}", product.name);
println!(" Product price: {}", product.price);
println!("\n3. Testing Database Configuration:");
println!(" Database tables count: {}", DATABASE.tables.len());
println!("\n4. Testing Index Information:");
let user_table = &DATABASE.tables[0];
println!(" User table name: {}", user_table.name);
println!(" User table primary key: {:?}", user_table.primary_key);
println!(
" User table secondary index: {:?}",
user_table.secondary_index
);
println!(
" User table secondary index type: {:?}",
user_table.secondary_index_type
);
let product_table = &DATABASE.tables[1];
println!(" Product table name: {}", product_table.name);
println!(
" Product table primary key: {:?}",
product_table.primary_key
);
println!(
" Product table secondary index: {:?}",
product_table.secondary_index
);
println!(
" Product table secondary index type: {:?}",
product_table.secondary_index_type
);
println!("\nDDL Index example completed successfully!");
}