-
Notifications
You must be signed in to change notification settings - Fork 2
Architecture
QueryBuilder is the most central class of the whole library.
One instance of QueryBuilder represents one query that is being generated.
An SQL query consists of clauses, each of which corresponds to one field of the respective QueryBuilder instance: scope (for the SELECT clause), from, where, orderBy, limit, offset.
An instance of QueryBuilder is initialized by calling from(TableName) where TableName is an object that extends Table (for details see Database schema definition).
The most important methods that modify the query are listed below.
Each of these methods takes a lambda function f: S => T as its only argument, where S <: Scope is a refined scope and T differs for each of the methods.
The map method updates the scope of the query.
The return type T of f is a subtype of Scope (i.e. the new scope itself). Alternatively, T can be a tuple of NamedExpressions, in which case a TupleScope is automatically created from the tuple.
The filter method updates the WHERE clause of the query.
The return type T of f is Expression[Boolean].
If the filter method is called multiple times, the resulting filtering condition will be a conjunction of all the predicates.
The sortBy method updates the ORDER BY clause of the query.
The return type T of f is either OrderBy or a tuple of OrderBys. OrderBy is either Asc(expression) or Desc(expression).