Skip to content
Ravi Teja Gudapati edited this page Jan 17, 2019 · 19 revisions

Find statement builder in Jaguar is equivalent to SQL's SELECT statement. It can be used to fetch one or multiple records from the database.

Selecting on table

The table is selected when a new Find builder is instantiated. In the example below, find statement will be executed on "people" table.

var find = Find("people");

Table alias

The alias parameter lets us pick an alias for the main table we are selecting on. This alias can be later used in column selection and where clauses in place of the original table name.

var find = Find("people", alias: 'p');

The above statement is equivalent to:

SELECT * FROM people as p;

Selecting columns

Selecting all columns

selAll method can be used to request fetching of all columns from the database.

var find = Find("people").selAll();

The above statement is equivalent to:

SELECT * FROM people AS p;

Use table optional parameter of selAll method to specify all columns of which table shall be fetched.

var find = Find("people").selAll('address');

The above statement is equivalent to:

SELECT address.* FROM people AS p ...;

Selecting columns by name

Individual columns can be selected using sel method.

var find = Find("people").sel('name').sel('age');

The above statement is equivalent to:

SELECT name, age FROM people;

Use alias optional parameter of sel method to select with what key the column will be returned as in the result.

var find = Find("people").sel('name', alias: 'n').sel('age', alias: 'a');

The above statement is equivalent to:

SELECT name AS n, age AS a FROM people;

The matching rows will be returned as:

{
  'n': 'Teja',
  'a': 29,
}

Selecting multiple columns with one call

TODO

Filtering

TODO

Joining

TODO

Executing the find statement

Person person = await find.exec(adapter).oneTo(Person.from);
Clone this wiki locally