Android OrmLite Complex Query

Dec 20, 2018
Grouping AND OR

The example below demanstate 3 AND condition, where the 2nd condition is an OR condition

final Dao<Image, String> dao = ...QueryBuilder queryBuilder = dao.queryBuilder();Where<Image, String> where = queryBuilder.where();where.and(where.isNotNull("local_file_path"),        where.or(where.isNotNull("blob_url"), where.eq("is_active", false)),        where.eq("is_local1600_cache", true));queryBuilder.orderBy("created", true);

Count

final Long count =queryBuilder.countOf()

Query

final List<Image> items = queryBuilder.query();

Query with limit

final List<Image> items = queryBuilder.limit((long)100).query();

Single field simple query

final List<Image> items = dao.queryForEq("is_active", true);

Query by id

Image item = dao.queryForId(imageId);

Batch Update

dao.callBatchTasks(new Callable<Void>() {    @Override    public Void call() throws Exception {        for (Image item : items) {            dao.update(item);        }        return null;    }});

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.