# FlareDB SQL Layer CRUD Example This example demonstrates the basic CRUD operations using the FlareDB SQL layer. ## Prerequisites 1. A running FlareDB server on `127.0.0.1:8001` 2. Rust toolchain installed ## What This Example Does The example performs the following operations: 1. **CREATE TABLE**: Creates a `users` table with columns (id, name, email, active) 2. **INSERT**: Inserts 4 sample users into the table 3. **SELECT \***: Queries all users 4. **SELECT with WHERE**: Queries only active users 5. **SELECT specific user**: Queries a single user by ID 6. **DROP TABLE**: Cleans up by dropping the table ## Running the Example ```bash # Navigate to the example directory cd docs/por/T037-flaredb-sql-layer/example-crud # Run the example cargo run --bin crud-example ``` ## Expected Output ``` === FlareDB SQL Layer CRUD Example === Connecting to FlareDB server at 127.0.0.1:8001... Connected! Step 1: Creating 'users' table... ✓ DdlSuccess("Table 'users' created") Step 2: Inserting users... ✓ Inserted: Alice Johnson - DmlSuccess(1) ✓ Inserted: Bob Smith - DmlSuccess(1) ✓ Inserted: Carol White - DmlSuccess(1) ✓ Inserted: Dave Brown - DmlSuccess(1) Step 3: Querying all users... ✓ Query result: QueryResult { columns: ["id", "name", "email", "active"], rows: [...] } Step 4: Querying active users only... ✓ Active users: QueryResult { columns: ["id", "name", "email", "active"], rows: [...] } Step 5: Querying user with id=2... ✓ Found user: QueryResult { columns: ["id", "name", "email", "active"], rows: [...] } Step 6: Dropping 'users' table... ✓ DdlSuccess("Table 'users' dropped") === Example completed === ``` ## Implementation Details The example uses: - `flaredb-client`: For connecting to the FlareDB server - `flaredb-sql`: For executing SQL statements All operations use strong consistency mode, ensuring ACID properties for SQL operations. ## Supported SQL Statements Current SQL layer implementation supports: - `CREATE TABLE` with primary key constraints - `DROP TABLE` - `INSERT INTO` with explicit column values - `SELECT` with column list or `*` - `WHERE` clause with comparison operators (=, <, >, <=, >=, !=) ## Future Enhancements Planned features include: - UPDATE and DELETE statements - JOIN operations - Aggregation functions (COUNT, SUM, AVG, etc.) - ORDER BY and LIMIT clauses - Indexes for query optimization