Build the query string without executing Returns the constructed GQL query as a string. # Examples ```no_run # use graphlite_sdk::GraphLite; # let db = GraphLite::open("./mydb")?; # let session = db.session("admin")?; let query = session.query_builder() .match_pattern("(p:Person)") .where_clause("p.age > 25") .return_clause("p.name") .build()?; assert_eq!(query, "MATCH (p:Person) WHERE p.age >
(&self)
| 249 | /// # Ok::<(), graphlite_sdk::Error>(()) |
| 250 | /// ``` |
| 251 | pub fn build(&self) -> Result<String> { |
| 252 | let mut query = String::new(); |
| 253 | |
| 254 | // MATCH clauses |
| 255 | if !self.match_patterns.is_empty() { |
| 256 | for pattern in &self.match_patterns { |
| 257 | if !query.is_empty() { |
| 258 | query.push(' '); |
| 259 | } |
| 260 | query.push_str("MATCH "); |
| 261 | query.push_str(pattern); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // WHERE clause |
| 266 | if !self.where_clauses.is_empty() { |
| 267 | query.push_str(" WHERE "); |
| 268 | query.push_str(&self.where_clauses.join(" AND ")); |
| 269 | } |
| 270 | |
| 271 | // WITH clauses |
| 272 | for with_clause in &self.with_clauses { |
| 273 | query.push_str(" WITH "); |
| 274 | query.push_str(with_clause); |
| 275 | } |
| 276 | |
| 277 | // RETURN clause |
| 278 | if let Some(ref return_clause) = self.return_clause { |
| 279 | query.push_str(" RETURN "); |
| 280 | query.push_str(return_clause); |
| 281 | } else if !self.match_patterns.is_empty() { |
| 282 | return Err(Error::InvalidOperation( |
| 283 | "MATCH query requires a RETURN clause".to_string(), |
| 284 | )); |
| 285 | } |
| 286 | |
| 287 | // ORDER BY |
| 288 | if let Some(ref order_by) = self.order_by { |
| 289 | query.push_str(" ORDER BY "); |
| 290 | query.push_str(order_by); |
| 291 | } |
| 292 | |
| 293 | // SKIP |
| 294 | if let Some(skip) = self.skip { |
| 295 | query.push_str(&format!(" SKIP {}", skip)); |
| 296 | } |
| 297 | |
| 298 | // LIMIT |
| 299 | if let Some(limit) = self.limit { |
| 300 | query.push_str(&format!(" LIMIT {}", limit)); |
| 301 | } |
| 302 | |
| 303 | Ok(query.trim().to_string()) |
| 304 | } |
| 305 | |
| 306 | /// Execute the query and return results |
| 307 | /// |