您可以在DBFlow中创建条件查询。要查询表格的列,您必须将_Table
附加到您的班级名称,然后访问其属性。这些_Table
类是在构建期间生成的。
最简单的查询会是这样一个:
SQLite.select()
.from(YourTable.class)
.where(YourTable_Table.id.eq(someId)
.queryList();
您也可以通过在查询中使用.and
和.or
添加新条件:
SQLite.select()
.from(YourTable.class)
.where(YourTable_Table.id.eq(someId)
.and(YourTable_Table.name.eq(someName)
.queryList();
对于一个更干净的代码,你也可以组条件进入如下条件组:
ConditionGroup conditionGroup = ConditionGroup.clause();
conditionGroup.and(YourTable_Table.id.eq(someId);
if (someCondition) {
conditionGroup.and(YourTable_Table.name.eq(someName);
}
return SQLite.select()
.from(YourTable.class)
.where(conditionGroup)
.queryList();
ConditionalGroup是我失踪了我的问题
1.从@trevjonez(特雷弗琼斯)
2.从@zshock两种方式... .thnks –