2

I am using greendao to work with sqlite database in my app.
I need to have such feature as where in condition
I am looking for such method or any other possible ways ,but without using raw query.

I need to perform such queries SELECT * FROM news WHERE id_company IN (SELECT id FROM company WHERE state=1.

Please suggest what is the best way to perform such query using GreenDAO ORM.

Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
CROSP
  • 4,499
  • 4
  • 38
  • 89
  • Here's the solution in the official documentation: http://greenrobot.org/greendao/documentation/queries/#Raw_queries – Miha_x64 Aug 08 '17 at 18:37

1 Answers1

4

You could use Lists.transform() from Guava as described here link

List<Company> companies = session.getCompanyDao()
                           .queryBuilder()
                           .where(CompanyDao.properties.state.eq(1))
                           .list();

Function<Company, Integer> companyToId = new Function<Company,Integer>() { 
    public String apply(Company c) { return c.getId(); }
};

List<Integer> ids = Lists.transform(companies, compnayToId);


session.getNewsDao()
.queryBuilder()
.where(NewsDao.Properties.id_company.in(ids))
.list();
Community
  • 1
  • 1
MoQ93
  • 341
  • 2
  • 12