- netboot-base.nix with SSH key auth - Launch scripts for node01/02/03 - Node configuration.nix and disko.nix - Nix modules for first-boot automation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
93 lines
3 KiB
Rust
93 lines
3 KiB
Rust
use flaredb_client::RdbClient;
|
|
use flaredb_sql::executor::SqlExecutor;
|
|
use std::sync::Arc;
|
|
use tokio::sync::Mutex;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
println!("=== FlareDB SQL Layer CRUD Example ===\n");
|
|
|
|
// Connect to FlareDB server
|
|
println!("Connecting to FlareDB server at 127.0.0.1:8001...");
|
|
let client = RdbClient::connect_direct("127.0.0.1:8001".to_string(), "demo".to_string()).await?;
|
|
let executor = SqlExecutor::new(Arc::new(Mutex::new(client)));
|
|
|
|
println!("Connected!\n");
|
|
|
|
// Step 1: Create a table
|
|
println!("Step 1: Creating 'users' table...");
|
|
let create_sql = "CREATE TABLE users (
|
|
id INTEGER PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
email TEXT NOT NULL,
|
|
active BOOLEAN
|
|
)";
|
|
|
|
match executor.execute(create_sql).await {
|
|
Ok(result) => println!("✓ {:?}\n", result),
|
|
Err(e) => println!("✗ Error: {} (table may already exist)\n", e),
|
|
}
|
|
|
|
// Step 2: Insert some data
|
|
println!("Step 2: Inserting users...");
|
|
let users = vec![
|
|
(1, "Alice Johnson", "alice@example.com", true),
|
|
(2, "Bob Smith", "bob@example.com", true),
|
|
(3, "Carol White", "carol@example.com", false),
|
|
(4, "Dave Brown", "dave@example.com", true),
|
|
];
|
|
|
|
for (id, name, email, active) in &users {
|
|
let insert_sql = format!(
|
|
"INSERT INTO users (id, name, email, active) VALUES ({}, '{}', '{}', {})",
|
|
id, name, email, active
|
|
);
|
|
|
|
match executor.execute(&insert_sql).await {
|
|
Ok(result) => println!("✓ Inserted: {} - {:?}", name, result),
|
|
Err(e) => println!("✗ Error inserting {}: {}", name, e),
|
|
}
|
|
}
|
|
println!();
|
|
|
|
// Step 3: Query all users
|
|
println!("Step 3: Querying all users...");
|
|
let select_all = "SELECT * FROM users";
|
|
match executor.execute(select_all).await {
|
|
Ok(result) => {
|
|
println!("✓ Query result:\n{:?}\n", result);
|
|
}
|
|
Err(e) => println!("✗ Error: {}\n", e),
|
|
}
|
|
|
|
// Step 4: Query with WHERE clause
|
|
println!("Step 4: Querying active users only...");
|
|
let select_active = "SELECT * FROM users WHERE active = true";
|
|
match executor.execute(select_active).await {
|
|
Ok(result) => {
|
|
println!("✓ Active users:\n{:?}\n", result);
|
|
}
|
|
Err(e) => println!("✗ Error: {}\n", e),
|
|
}
|
|
|
|
// Step 5: Query specific user
|
|
println!("Step 5: Querying user with id=2...");
|
|
let select_one = "SELECT * FROM users WHERE id = 2";
|
|
match executor.execute(select_one).await {
|
|
Ok(result) => {
|
|
println!("✓ Found user:\n{:?}\n", result);
|
|
}
|
|
Err(e) => println!("✗ Error: {}\n", e),
|
|
}
|
|
|
|
// Step 6: Drop table (cleanup)
|
|
println!("Step 6: Dropping 'users' table...");
|
|
let drop_sql = "DROP TABLE users";
|
|
match executor.execute(drop_sql).await {
|
|
Ok(result) => println!("✓ {:?}\n", result),
|
|
Err(e) => println!("✗ Error: {}\n", e),
|
|
}
|
|
|
|
println!("=== Example completed ===");
|
|
Ok(())
|
|
}
|