Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete rows from GreenDao based on condition?

i want to delete rows from a table based on condition. like

"delete from Table where Name='Value'"

here i am using greenDAO database.

like image 958
rashmi ranjan Avatar asked Apr 10 '17 12:04

rashmi ranjan


1 Answers

1 Check the documentation.

2 Create a DeleteQuery for your Table

3 Execute it

4 Clear the session so that all caches lose the deleted objects too.

final DeleteQuery<Table> tableDeleteQuery = daoSession.queryBuilder(Table.class)
.where(TableDao.Properties.Name.eq("Value"))
.buildDelete();
tableDeleteQuery.executeDeleteWithoutDetachingEntities();
daoSession.clear();

If you need to execute the query multiple times, save the query object to avoid re-instantiating it.

Btw greenDAO is an ORM, not a database (here it's SQLite).

like image 97
w_n Avatar answered Sep 18 '22 01:09

w_n