简体   繁体   English

在 ObjectBox 中存储原始值

[英]Storing primitive values in ObjectBox

I am fetching orders from a backend that has two endpoints, one for fetching a limited number of orders and one for fetching simply the number of total orders available.我正在从具有两个端点的后端获取订单,一个用于获取有限数量的订单,另一个用于仅获取可用订单的总数。 I can store the orders using a CustomerOrder entity class but how can I store the primitive count value?我可以使用 CustomerOrder 实体类存储订单,但如何存储原始计数值?

Since ObjectBox will not allow boxes of primitive types and requires using entity classes I had to wrap a single (!) Integer inside an entity class.由于 ObjectBox 不允许原始类型的盒子并且需要使用实体类,因此我不得不在实体类中包装一个 (!) Integer。 Maybe there is a simpler way to do this?也许有更简单的方法来做到这一点?

What does not work but what I basically want to do:什么不起作用,但我基本上想做的是:

Box<Integer> countBox = boxStore.boxFor(Integer.class);

My current entity wrapper class (still only uses 1 row in the table):我当前的实体包装类(仍然只使用表中的 1 行):

@Entity
public class CustomerOrderCount {

    @Id
    public Integer count;
}

I simply want to follow best practices and simplify things.我只是想遵循最佳实践并简化事情。 Maybe there is an even easier method than using ObjectBox that is still legit that I am not seeing here.也许有一种比使用 ObjectBox 更简单的方法,但我在这里没有看到它仍然是合法的。

For this can go for SharedPreferences .为此可以选择SharedPreferences

Or if you have too many primitive values to store you can go for LevelDB或者,如果您有太多原始值要存储,您可以使用LevelDB

From the docs:从文档:

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. LevelDB 是一个由 Google 编写的快速键值存储库,它提供了从字符串键到字符串值的有序映射。

The android bindings for LevelDB are available here . LevelDB 的 android 绑定可在此处获得

You can also use Hawk .您也可以使用Hawk It's another simple key value storage for Android.它是 Android 的另一个简单的键值存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM