Skip to main content

QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder<'session> { /* private fields */ }
Expand description

Fluent API for building GQL queries

QueryBuilder provides a convenient way to construct complex GQL queries without manually concatenating strings.

§Examples

// Using the builder
let result = session.query_builder()
    .match_pattern("(p:Person)")
    .where_clause("p.age > 25")
    .return_clause("p.name, p.age")
    .execute()?;

// Equivalent to:
// "MATCH (p:Person) WHERE p.age > 25 RETURN p.name, p.age"

Implementations§

Source§

impl<'session> QueryBuilder<'session>

Source

pub fn match_pattern(self, pattern: &str) -> Self

Add a MATCH pattern

Can be called multiple times to add multiple MATCH patterns.

§Arguments
  • pattern - Graph pattern to match (without the MATCH keyword)
§Examples
session.query_builder()
    .match_pattern("(p:Person)")
    .match_pattern("(p)-[:KNOWS]->(f:Person)")
    .return_clause("p.name, f.name");
Source

pub fn where_clause(self, condition: &str) -> Self

Add a WHERE clause condition

Can be called multiple times - conditions are AND’ed together.

§Arguments
  • condition - Condition to add (without the WHERE keyword)
§Examples
session.query_builder()
    .match_pattern("(p:Person)")
    .where_clause("p.age > 25")
    .where_clause("p.name STARTS WITH 'A'")
    .return_clause("p");
Source

pub fn with_clause(self, clause: &str) -> Self

Add a WITH clause

WITH clauses are used for query chaining and intermediate results.

§Arguments
  • clause - WITH clause content (without the WITH keyword)
§Examples
session.query_builder()
    .match_pattern("(p:Person)")
    .with_clause("p, p.age as age")
    .where_clause("age > 25")
    .return_clause("p.name");
Source

pub fn return_clause(self, clause: &str) -> Self

Set the RETURN clause

Specifies what to return from the query. Required for MATCH queries.

§Arguments
  • clause - Return clause content (without the RETURN keyword)
§Examples
session.query_builder()
    .match_pattern("(p:Person)")
    .return_clause("p.name, p.age");
Source

pub fn order_by(self, clause: &str) -> Self

Set the ORDER BY clause

§Arguments
  • clause - Order by clause (without the ORDER BY keywords)
§Examples
session.query_builder()
    .match_pattern("(p:Person)")
    .return_clause("p.name, p.age")
    .order_by("p.age DESC");
Source

pub fn skip(self, n: usize) -> Self

Set the SKIP value

Skips the first N results.

§Arguments
  • n - Number of results to skip
§Examples
session.query_builder()
    .match_pattern("(p:Person)")
    .return_clause("p")
    .skip(10);  // Skip first 10 results
Source

pub fn limit(self, n: usize) -> Self

Set the LIMIT value

Limits the number of results returned.

§Arguments
  • n - Maximum number of results to return
§Examples
session.query_builder()
    .match_pattern("(p:Person)")
    .return_clause("p")
    .limit(10);  // Return max 10 results
Source

pub fn build(&self) -> Result<String>

Build the query string without executing

Returns the constructed GQL query as a string.

§Examples
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 > 25 RETURN p.name");
Source

pub fn execute(&self) -> Result<QueryResult>

Execute the query and return results

Builds and executes the query in one step.

§Examples
let result = session.query_builder()
    .match_pattern("(p:Person)")
    .where_clause("p.age > 25")
    .return_clause("p.name, p.age")
    .limit(10)
    .execute()?;

for row in result.rows() {
    println!("{:?}", row);
}

Auto Trait Implementations§

§

impl<'session> Freeze for QueryBuilder<'session>

§

impl<'session> RefUnwindSafe for QueryBuilder<'session>

§

impl<'session> Send for QueryBuilder<'session>

§

impl<'session> Sync for QueryBuilder<'session>

§

impl<'session> Unpin for QueryBuilder<'session>

§

impl<'session> UnsafeUnpin for QueryBuilder<'session>

§

impl<'session> UnwindSafe for QueryBuilder<'session>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.