Support and Documentation

Binding variables of simple types

In a basic scenario, placeholders refer to variables with single values or single objects, such as String, Integer, or Date.

 String userName = "John Smith";
 User user = Query.from(User.class)
                  .where("name = ?", userName).first();

Referring to the previous snippet, at runtime Dari creates the following where clause:

WHERE name = 'John Smith'

In the next example, the query filters on a Date object, returning all ToolUsers for which the last login date is after January 17, 2019.

 String startDateString = "01/17/2019";
 DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
 Date date = null;

 try {
     date = df.parse(startDateString);
 catch (ParseException e) {
     /* Error handling */

 List<ToolUser> toolUser = Query.from(ToolUser.class)
                                 .where("lastLoginDate  >  ?", date).selectAll();