ObjectBox - select 只有一些列

ObjectBox - select only some columns

假设我有一个像这样的 ObjectBox 实体:

@Entity
public class CountryEntity {

    @Id
    private long entityId;

    private String name;
    private float area;
    private int population;
    private String subRegion;
    private String region;
    private String code3;
    private String capitalCity;

    setters, getters }


和一个查询:

public ObjectBoxLiveData<CountryEntity> getAllCountries(){
       Box<CountryEntity> countryBox = boxStore.boxFor(CountryEntity.class);
       return new ObjectBoxLiveData<CountryEntity>(
               countryBox.query().order(CountryEntity_.name).build());
   }

这 select 是所有国家/地区。有没有办法 select 只有一些 "columns" 例如。例如 namearea 而不是其他的?

我常常不需要所有列,而是需要一个子集,我对不必要地查询所有数据感到非常内疚。

谢谢!

不用太担心。 ObjectBox 创建对象的速度非常快(可能比其他解决方案快 10 倍)。所以除非你携带例如大型二进制对象你应该没问题。

要查询单个属性,您可能已经看到 property queries

否则,您可能希望为以下功能请求投票: https://github.com/objectbox/objectbox-java/issues/348