您可以在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 –