Android GreenDao framework uses queryBuilder in advanced articles

reference

Official document

Github

series

Android GreenDao framework use basic articles
Android GreenDao framework use additions, deletions, revisions and investigation articles

The usage of queryBuilder can be executed through chain instructions, such as

testUserDao.queryBuilder().xx.xx.xx.结束指令。

Regarding the end instruction, as shown below

method Explanation
.list() Query eligible data
.buildDelete().executeDeleteWithoutDetachingEntities() Delete eligible data
.count() Query the number of eligible

Of course there are more than these, these are more common.

Regarding conditional query, GreenDao provides many methods

method Explanation
where Query conditions (the conditions in where must all be met)
whereOr Query conditions (if the conditions in where are met)
offset Ignore the first n results of the query
orderAsc Ascending
orderDesc descending sort

The following is the method in the conditional query

method condition
eq ==
notEq !=
like Fuzzy query
between Interval of two values
in Range interval
notIn Out of range
gt >
lt <
give >=
the <=
isNull Is empty
isNotNull not null

example

 testUserDao.queryBuilder().where(TestUserDao.Properties.Name.eq(name),TestUserDao.Properties.Age.eq(12)).list();
 testUserDao.queryBuilder().whereOr(TestUserDao.Properties.Name.eq(name),TestUserDao.Properties.Age.eq(12)).list();

Whether it is where or whereOr, there can be one or more judgment sentences. The difference is that where is the relationship of "and", while whereOr is the relationship of "or".

 QueryBuilder<TestUser> qb = testUserDao.queryBuilder();
 List<TestUser> testUsers = qb.where(qb.and(TestUserDao.Properties.Name.eq(name),TestUserDao.Properties.Age.eq(12))).list();
 QueryBuilder<TestUser> qb = testUserDao.queryBuilder();
 List<TestUser> testUsers = qb.where(TestUserDao.Properties.Name.eq(name),qb.or(TestUserDao.Properties.Age.eq(12),TestUserDao.Properties.Age.eq(15))).list();

At the same time, you can also write complex statements in where and whereOr, so that you can implement multi-condition nested queries.

Guess you like

Origin blog.csdn.net/m0_48440239/article/details/114301745