-
Notifications
You must be signed in to change notification settings - Fork 4
ITable
ITable
represents a table inside the database. To access the table simply call
...
IDatabase db = ...
ITable table = db.get("<table-name>");
...
ITable
object, once created, is automatically cached inside the IDatabase
. So there's no need to reference it outside. Most of the time db.get("tableName").<someMethod>()
is more preferable to use.
ITable
does not store any table structure or any data whatsoever. It only stores its name, alias (if any) and column names. So it's easy on the memory usage.
ITable
provides common methods to perform many CRUD and other common tasks such as (functions, count, etc...). This is the object that you will reference to access and manipulate the data with.
#Operations
#ITable.count()
-
ITable.count()
returns the total records inside the table. Equivalent to callingSELECT COUNT(*) IN Table
in SQL -
ITable.count(String condition)
returns the total records inside the table that matches the specified condition. Equivalent to callingSELECT COUNT(*) IN Table WHERE...
-
ITable.count(String whereClause, Object... args)
returns the total records inside the table that matches thewhereClause
. This is more preferred way then callingcount(condition)
.
#ITable.has()
This is a convenient method to check for a record existence in a table.
-
ITable.has(int id)
returnstrue
if table has a record with the sameid
;false
if otherwise -
ITable.has(String condition)
returnstrue
if table has a record or more that satisfy the condition;false
if otherwise -
ITable.has(String whereClause, Object... args)
returnstrue
if table has a record or more that satisfy the specifiedwhereClause
; false if otherwise
This is a convenient method to query your manual SQL script:
String sql = ...
Cursor cursor = db.get("Table")
.raw(sql)
.query();
// or
Cursor cursor = db.get("Table")
.raw(sql, [args]...)
.query();
#Functions
-
AVG
Returns the average value in a specific column inside the table. Equivalent to callingSELECT AVG(column) FROM table
. Use the following
int avg = db.get("table").avg("columnName").asInt(); // rounded as integer
float avg = db.get("table").avg("columnName").asFloat(); // as float
-
SUM
Returns the sum (total) value in a specific column inside the table. Equivalent of callingSELECT SUM(column) FROM table
. Use the following
int sum = db.get("table").sum("columnName").asInt(); // rounded as integer
float sum = db.get("table").sum("columnName").asFloat(); // as float
-
MAX
Returns the maximum value in a specific column inside the table. Equivalent to callingSELECT MAX(column) FROM table
. Use the following
int max = db.get("table").max("columnName").asInt(); // rounded as integer
float max = db.get("table").max("columnName").asFloat(); // as float
-
MIN
Returns the minimum value in a specific column inside the table. Equivalent to callingSELECT MIN(column) FROM table
. Use the following
int min = db.get("table").min("columnName").asInt(); // rounded as integer
float min = db.get("table").min("columnName").asFloat(); // as float