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")

Start a DELETE statement:

DELETE user:John
Example
use surreal_simple_querybuilder::prelude::*;

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

assert_eq!(query, "DELETE ee:Person");

Start a RELATE statement:

RELATE user:tobie->write->article:surreal SET time.written = time::now();

Note: the SET or anything after it in the example above should be added manually using the QueryBuilder::set() method.

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new().relate("user:John->likes->user:Mark").build();

assert_eq!(query, "RELATE user:John->likes->user:Mark");

Start a CONTENT statement. Content statements often follow RELATE statements:

RELATE user:tobie->write->article:surreal CONTENT {
  source: 'Apple notes',
  tags: ['notes', 'markdown'],
  time: {
    written: time::now(),
  },
};

Note: Anything before the CONTENT in the example above should be added manually using the QueryBuilder::relate() method.

Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new().content("{ creation_time: time::now() }").build();

assert_eq!(query, "CONTENT { creation_time: time::now() }");
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

Writes a OR followed by the supplied condition

Example
use surreal_simple_querybuilder::prelude::*;

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

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

Starts an AND followed by the supplied condition.

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");

Starts a GROUP BY clause,

Example
use surreal_simple_querybuilder::prelude::*;

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

assert_eq!(query, "GROUP BY author");

Starts a GROUP BY clause with zero or more fields,

Example
use surreal_simple_querybuilder::prelude::*;

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

assert_eq!(query, "GROUP BY author , projects");

Starts a ORDER BY ASC clause,

Example
use surreal_simple_querybuilder::prelude::*;

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

assert_eq!(query, "ORDER BY author ASC");

Starts a ORDER BY ASC clause with zero or more fields,

Example
use surreal_simple_querybuilder::prelude::*;

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

assert_eq!(query, "ORDER BY author ASC , projects ASC");

Starts a ORDER BY DESC clause,

Example
use surreal_simple_querybuilder::prelude::*;

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

assert_eq!(query, "ORDER BY author DESC");

Starts a ORDER BY DESC clause with zero or more fields,

Example
use surreal_simple_querybuilder::prelude::*;

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

assert_eq!(query, "ORDER BY author DESC , projects DESC");

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");

Writes an AND followed by the supplied first_condition and any other statement added to the querybuilder in the action closure surrounded by parenthesis.

Can be used to compose boolean expressions with grouped OR statements like so:

WHERE name contains 'John' AND (name contains 'Doe' OR name contains 'Eod')
Example
use surreal_simple_querybuilder::prelude::*;

let query = QueryBuilder::new()
  .select("*")
  .from("user")
  .filter("name contains 'John'")
  .and_group("name contains 'Doe'", |q| {
    q.or("name contains 'Eod'")
  })
  .build();

assert_eq!(query, "SELECT * FROM user WHERE name contains 'John' AND ( name contains 'Doe' OR name contains 'Eod' )");

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);

Start a SET statement with all the public fields in the supplied T using the [SqlFieldSerializer] and Serde to list all the serializable fields in order to get a statement like the following:

SET field_one = $field_one , field_two = $field_two

The function is meant to be used with the models generated by the [model] macro.

Start an UPDATE statement with all the public fields in the supplied T using the [SqlFieldSerializer] and Serde to list all the serializable fields in order to get a statement like the following:

UPDATE field_one = $field_one , field_two = $field_two

The function is meant to be used with the models generated by the [model] macro.

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.