()
| 21 | } |
| 22 | |
| 23 | fn main() -> Result<(), Error> { |
| 24 | println!("=== GraphLite SDK Basic Usage Example ===\n"); |
| 25 | |
| 26 | // 1. Open a database |
| 27 | println!("1. Opening database..."); |
| 28 | let db_path = "/tmp/graphlite_sdk_example"; |
| 29 | let db = GraphLite::open(db_path)?; |
| 30 | println!(" ✓ Database opened at {}\n", db_path); |
| 31 | |
| 32 | // 2. Create a session |
| 33 | println!("2. Creating session..."); |
| 34 | let session = db.session("admin")?; |
| 35 | println!(" ✓ Session created for user 'admin'\n"); |
| 36 | |
| 37 | // 3. Execute DDL statements |
| 38 | println!("3. Creating schema and graph..."); |
| 39 | session.execute("CREATE SCHEMA IF NOT EXISTS example")?; |
| 40 | session.execute("USE SCHEMA example")?; |
| 41 | session.execute("CREATE GRAPH IF NOT EXISTS social")?; |
| 42 | session.execute("USE GRAPH social")?; |
| 43 | println!(" ✓ Schema and graph created\n"); |
| 44 | |
| 45 | // 4. Insert data using transactions |
| 46 | println!("4. Inserting data with transaction..."); |
| 47 | { |
| 48 | let mut tx = session.transaction()?; |
| 49 | tx.execute("CREATE (p:Person {name: 'Alice', age: 30})")?; |
| 50 | tx.execute("CREATE (p:Person {name: 'Bob', age: 25})")?; |
| 51 | tx.execute("CREATE (p:Person {name: 'Charlie', age: 35})")?; |
| 52 | tx.commit()?; |
| 53 | println!(" ✓ Inserted 3 persons\n"); |
| 54 | } |
| 55 | |
| 56 | // 5. Query data directly |
| 57 | println!("5. Querying data..."); |
| 58 | let result = session.query("MATCH (p:Person) RETURN p.name as name, p.age as age")?; |
| 59 | println!(" Found {} persons:", result.rows.len()); |
| 60 | for row in &result.rows { |
| 61 | if let (Some(name), Some(age)) = (row.get_value("name"), row.get_value("age")) { |
| 62 | println!(" - Name: {:?}, Age: {:?}", name, age); |
| 63 | } |
| 64 | } |
| 65 | println!(); |
| 66 | |
| 67 | // 6. Use query builder |
| 68 | println!("6. Using query builder..."); |
| 69 | let result = session |
| 70 | .query_builder() |
| 71 | .match_pattern("(p:Person)") |
| 72 | .where_clause("p.age > 25") |
| 73 | .return_clause("p.name as name, p.age as age") |
| 74 | .order_by("p.age DESC") |
| 75 | .execute()?; |
| 76 | println!(" Found {} persons over 25:", result.rows.len()); |
| 77 | for row in &result.rows { |
| 78 | if let (Some(name), Some(age)) = (row.get_value("name"), row.get_value("age")) { |
| 79 | println!(" - Name: {:?}, Age: {:?}", name, age); |
| 80 | } |
nothing calls this directly
no test coverage detected