Skip to content

jSQLWhereClause class

Pamblam edited this page Dec 11, 2016 · 3 revisions

For query types that have a where clause ("DELETE", "SELECT", and "UPDATE"), this method is accessed via the query's where() method. This is used to filter and sort results in a "SELECT" query or the results to be edited or delete with "DELETE" and "UPDATE" queries.


jSQLWhereClause.where(column)

Set a column to add a filter to.

Parameters
  • column: The column to be used in the filter.
Returns
Example
var allSusans =
     jSQL.select('*')
    .from('Users')
    .where('Name')
    .equals('Susan')
    .execute()
    .fetchAll();

jSQLWhereClause.equals(value)

Filter results to ones where the filtered column matches the given value

Parameters
  • value: The value to be used in the filter.
Returns
Example
var OldUsers =
     jSQL.select(['Name', 'Age'])
    .from('Users')
    .where('Age')
    .equals(37)
    .execute()
    .fetchAll();

jSQLWhereClause.preparedLike()

For use with "LIKE" modifiers which are used with a prepared query.

Returns
Example
var PatrioticUsers =
     jSQL.select(['Name', 'Age'])
    .from('Users')
    .where('Name')
    .preparedLike()
    .execute(['%usa%'])
    .fetchAll();

jSQLWhereClause.doesNotEqual(value)

Filter results to ones where the filtered column does not match the given value

Parameters
  • value: The value to be used in the filter.
Returns
Example
var EveryoneButSusan =
     jSQL.select(['Name', 'Age'])
    .from('Users')
    .where('Name')
    .doesNotEqual('Susan')
    .execute()
    .fetchAll();

jSQLWhereClause.lessThan(value)

Filter results to ones where the filtered column is less than the given value

Parameters
  • value: The value to be used in the filter.
Returns
Example
var hipsters =
     jSQL.select(['Name'])
    .from('Users')
    .where('Age')
    .lessThan(23)
    .execute()
    .fetchAll();

jSQLWhereClause.contains(value)

Filter results to ones where the filtered column contains the given substring.

Parameters
  • value: The value to be used in the filter.
Returns
Example
var UsersLikeBob =
     jSQL.select(['Name'])
    .from('Users')
    .where('Name')
    .contains('bob')
    .execute()
    .fetchAll();

jSQLWhereClause.endsWith(value)

Filter results to ones where the filtered column ends with the given substring.

Parameters
  • value: The value to be used in the filter.
Returns
Example
var nameEndsWithB =
     jSQL.select(['Name'])
    .from('Users')
    .where('Name')
    .endsWith('b')
    .execute()
    .fetchAll();

jSQLWhereClause.beginsWith(value)

Filter results to ones where the filtered column begins with the given substring.

Parameters
  • value: The value to be used in the filter.
Returns
Example
var nameBeginsWithB =
     jSQL.select(['Name'])
    .from('Users')
    .where('Name')
    .beginsWith('b')
    .execute()
    .fetchAll();

jSQLWhereClause.and(column)

Begin an additional condition. Results must match both this condition and the preceeding one.

Parameters
  • column: The column to be used in the filter.
Returns
Example
var nameBeginsAndEndsWithB =
     jSQL.select(['Name'])
    .from('Users')
    .where('Name')
    .beginsWith('b')
    .and('Name')
    .endsWith('b')
    .execute()
    .fetchAll();

jSQLWhereClause.or(column)

Begin an additional condition. Results must match either this condition or the preceeding one.

Parameters
  • column: The column to be used in the filter.
Returns
Example
var nameBeginsOrEndsWithB =
     jSQL.select(['Name'])
    .from('Users')
    .where('Name')
    .beginsWith('b')
    .or('Name')
    .endsWith('b')
    .execute()
    .fetchAll();

jSQLWhereClause.limit(limit)

Limit the rows returned, deleted, or updated.

Parameters
  • limit: The number of rows to limit to.
Returns
Example
var first3Users =
     jSQL.select('Name')
    .from('Users')
    .limit(3)
    .execute()
    .fetchAll();

jSQLWhereClause.orderBy(column)

Sort the result set. Only useful for "SELECT" queries.

Parameters
  • column: The column or columns to order results by
Returns
Example
var first3Users =
     jSQL.select('Name')
    .from('Users')
    .limit(3)
    .orderBy('Name')
    .asc()
    .execute()
    .fetchAll();

jSQLWhereClause.asc()

Sort the result set ASCENDING. Only useful for "SELECT" queries.

Returns
Example
var first3Users =
     jSQL.select('*')
    .from('Users')
    .limit(3)
    .orderBy('Name')
    .asc()
    .execute()
    .fetchAll();

jSQLWhereClause.desc()

Sort the result set DESCENDING. Only useful for "SELECT" queries.

Returns
Example
var first3Users =
     jSQL.select('*')
    .from('Users')
    .limit(3)
    .orderBy('Name')
    .desc()
    .execute()
    .fetchAll();

jSQLWhereClause.execute()

Builds the result set based on conditions and prepared values provided and then executes the query's execute method and returns the query itself rather than the query's where clause.

Returns
Example
var allUsers =
     jSQL.select('*')
    .from('Users')
    .execute()
    .fetchAll();

Clone this wiki locally