/** * Declaring how to order the rows queried from table. * * <pre> * LitePal.order("name desc").find(Person.class); * </pre> * * This will find all rows in Person table sorted by name with inverted * order. * * @param column * How to order the rows, formatted as an SQL ORDER BY clause. * Passing null will use the default sort order, which may be * unordered. * @return A FluentQuery instance. */ public static FluentQuery order(String column) { FluentQuery cQuery = new FluentQuery(); cQuery.mOrderBy = column; return cQuery; }
/** * Declaring to query which columns in table. * * <pre> * LitePal.select("name", "age").find(Person.class); * </pre> * * This will find all rows with name and age columns in Person table. * * @param columns * A String array of which columns to return. Passing null will * return all columns. * * @return A FluentQuery instance. */ public static FluentQuery select(String... columns) { FluentQuery cQuery = new FluentQuery(); cQuery.mColumns = columns; return cQuery; }
/** * Declaring to query which rows in table. * * <pre> * LitePal.where("name = ? or age > ?", "Tom", "14").find(Person.class); * </pre> * * This will find rows which name is Tom or age greater than 14 in Person * table. * * @param conditions * A filter declaring which rows to return, formatted as an SQL * WHERE clause. Passing null will return all rows. * @return A FluentQuery instance. */ public static FluentQuery where(String... conditions) { FluentQuery cQuery = new FluentQuery(); cQuery.mConditions = conditions; return cQuery; }
/** * Declaring the offset of rows returned by the query. This method must be * used with {@link #limit(int)}, or nothing will return. * * <pre> * LitePal.limit(1).offset(2).find(Person.class); * </pre> * * This will find the third row in Person table. * * @param value * The offset amount of rows returned by the query. * @return A FluentQuery instance. */ public static FluentQuery offset(int value) { FluentQuery cQuery = new FluentQuery(); cQuery.mOffset = String.valueOf(value); return cQuery; }
/** * Limits the number of rows returned by the query. * * <pre> * LitePal.limit(2).find(Person.class); * </pre> * * This will find the top 2 rows in Person table. * * @param value * Limits the number of rows returned by the query, formatted as * LIMIT clause. * @return A FluentQuery instance. */ public static FluentQuery limit(int value) { FluentQuery cQuery = new FluentQuery(); cQuery.mLimit = String.valueOf(value); return cQuery; }
/** * Count the records. * * <pre> * LitePal.count("person"); * </pre> * * This will count all rows in person table.<br> * You can also specify a where clause when counting. * * <pre> * LitePal.where("age > ?", "15").count("person"); * </pre> * * @param tableName * Which table to query from. * @return Count of the specified table. */ public static int count(String tableName) { synchronized (LitePalSupport.class) { FluentQuery cQuery = new FluentQuery(); return cQuery.count(tableName); } }
/** * Calculates the average value on a given column. * * <pre> * LitePal.average("person", "age"); * </pre> * * You can also specify a where clause when calculating. * * <pre> * LitePal.where("age > ?", "15").average("person", "age"); * </pre> * * @param tableName * Which table to query from. * @param column * The based on column to calculate. * @return The average value on a given column. */ public static double average(String tableName, String column) { synchronized (LitePalSupport.class) { FluentQuery cQuery = new FluentQuery(); return cQuery.average(tableName, column); } }
/** * Calculates the sum of values on a given column. The value is returned * with the same data type of the column. * * <pre> * LitePal.sum("person", "age", int.class); * </pre> * * You can also specify a where clause when calculating. * * <pre> * LitePal.where("age > ?", "15").sum("person", "age", Integer.TYPE); * </pre> * * @param tableName * Which table to query from. * @param columnName * The based on column to calculate. * @param columnType * The type of the based on column. * @return The sum value on a given column. */ public static <T> T sum(String tableName, String columnName, Class<T> columnType) { synchronized (LitePalSupport.class) { FluentQuery cQuery = new FluentQuery(); return cQuery.sum(tableName, columnName, columnType); } }
/** * Calculates the maximum value on a given column. The value is returned * with the same data type of the column. * * <pre> * LitePal.max("person", "age", int.class); * </pre> * * You can also specify a where clause when calculating. * * <pre> * LitePal.where("age > ?", "15").max("person", "age", Integer.TYPE); * </pre> * * @param tableName * Which table to query from. * @param columnName * The based on column to calculate. * @param columnType * The type of the based on column. * @return The maximum value on a given column. */ public static <T> T max(String tableName, String columnName, Class<T> columnType) { synchronized (LitePalSupport.class) { FluentQuery cQuery = new FluentQuery(); return cQuery.max(tableName, columnName, columnType); } }
/** * Calculates the minimum value on a given column. The value is returned * with the same data type of the column. * * <pre> * LitePal.min("person", "age", int.class); * </pre> * * You can also specify a where clause when calculating. * * <pre> * LitePal.where("age > ?", "15").min("person", "age", Integer.TYPE); * </pre> * * @param tableName * Which table to query from. * @param columnName * The based on column to calculate. * @param columnType * The type of the based on column. * @return The minimum value on a given column. */ public static <T> T min(String tableName, String columnName, Class<T> columnType) { synchronized (LitePalSupport.class) { FluentQuery cQuery = new FluentQuery(); return cQuery.min(tableName, columnName, columnType); } }