[][src]Module toql_core::sql_builder

The SQL Builder turns a Query with the help of a SQL Mapper into a Sql Builder Result The result hold the different parts of an SQL query and can be turned into an SQL query that can be sent to the database.


This example is not tested
let  query = Query::wildcard().and(Field::from("foo").eq(5));
let mapper::new("Bar b").map_field("foo", "b.foo");
let builder_result = QueryBuilder::new().build_query(&mapper, &query);
assert_eq!("SELECT b.foo FROM Bar b WHERE b.foo = ?", builder_result.to_sql());
assert_eq!(["5"], builder_result.params());

The SQL Builder can also add joins if needed. Joins must be registered on the SQL Mapper for this.

Count queries

Besides normal queries the SQL Builder can als build count queries.

Let's assume you have a grid view with books and the user enters a search term to filter your grid. The normal query will get 50 books, but you will only display 10 books. Toql calls those 50 the filtered count. To get the unfilted count, Toql must issue another query with different filter settings. Typically to get the number of all books only that user has access to. Toql calls this the total count.


The SQL Builder can also ignore paths to skip paths in the query that are not mapped in the mapper. This is needed for structs that contain collections, as these collections must be querried with a different mapper.

Let's assume a struct user had a collection of phones. The Toql query may look like: username, phones_number. The SQL Builder needs 2 passes to resolve that query:

  • The first pass will query all users with the user mapper and will ignore the path phones_.
  • The second pass will only build the query for the path phones_ with the help of the phone mapper.



The Sql builder to build normal queries and count queries.



Represents all errors from the SQL Builder