pub struct QueryBuilder<'a> { /* private fields */ }

Implementations

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new().create("Person:ee").build();

assert_eq!(query, "CREATE Person:ee")
Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new().update("Person:ee").build();

assert_eq!(query, "UPDATE Person:ee")
Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new().select("ee:Person").build();

assert_eq!(query, "SELECT ee:Person")
Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new().from("Person").build();

assert_eq!(query, "FROM Person")
Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new().select_many(&["ee:Person", "o:Order"]).build();

assert_eq!(query, "SELECT ee:Person , o:Order")

Adds the supplied query with a comma in front of it

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new().also(&"ee").build();

assert_eq!(query, ", ee")

Starts a WHERE clause.

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .filter("handle = ?1")
  .build();

assert_eq!(query, "WHERE handle = ?1");

An alias for QueryBuilder::filter

Starts a WHERE clause.

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .and("handle = ?1")
  .build();

assert_eq!(query, "AND handle = ?1");

Starts a SET clause.

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .set("handle = ?1")
  .build();

assert_eq!(query, "SET handle = ?1");

Starts a SET clause with many fields.

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .set_many(&["handle = $1", "password = $2"])
  .build();

assert_eq!(query, "SET handle = $1 , password = $2");

Starts a FETCH clause,

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .fetch("author")
  .build();

assert_eq!(query, "FETCH author");

Starts a FETCH clause with zero or more fields,

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .fetch_many(&["author", "projects"])
  .build();

assert_eq!(query, "FETCH author , projects");

Queues a condition which allows the next statement to be ignored if condition is false.

Conditions can be nested, the queue works as a LIFO queue.

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .select_many(&["1", "2"])
  .if_then(false, |query| query
    .select_many(&["3", "4"])
    // will not run:
    .if_then(true, |query| query
      .select_many(&["5", "6"])
    )
  )
  .if_then(true, |query| query
    .select_many(&["7", "8"])
  )
  .build();

assert_eq!(query, "SELECT 1 , 2 SELECT 7 , 8");

Pushes raw text to the buffer

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .raw("foo bar")
  .build();

assert_eq!(query, "foo bar");

Start a queue where all of the new pushed actions are separated by commas.

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .commas(|query| query
    .raw("foo")
    .raw("bar")
  ).build();

assert_eq!(query, "foo , bar");

Start a LIMIT clause.

Example
use surreal_simple_querybuilder::prelude::*;


let page_size = 10.to_string();
let query = QueryBuilder::new()
  .limit(&page_size)
  .build();

assert_eq!(query, "LIMIT 10")

Start a START AT clause.

Example
use surreal_simple_querybuilder::prelude::*;


let page_size = 10.to_string();
let query = QueryBuilder::new()
  .start_at(&page_size)
  .build();

assert_eq!(query, "START AT 10")

Add the given segment to the internal buffer. This is a rather internal method that is set public for special cases, you should prefer using the raw method instead.

Add a parameter and its value to the query that will be used to replace all occurences of key into value when the build method is called.

IMPORTANT Do not use this for user provided data, the input is not sanitized

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .select("{{field}}")
  .from("Account")
  .param("{{field}}", "id")
  .build();

assert_eq!("SELECT id FROM Account", query);

Tell the current query builder to execute the QueryBuilderSetObject trait for the given T generic type.

Tell the current querybuilder to hold the given string into its internal buffer and to return a reference to the newly held value a QueryBuilder can use.

This function is particularely useful if some of your code is inside a short-lived scope such as a closure but you still need to add segments to the querybuilder. However the fact the querybuilder initially holds series of &'a str makes it impossible, this is where you can tell the builder to hold the given string for you.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.