objectboxflutter-objectbox

How can I have multiple boxes of the same type?


I want to store the same type of information in different boxes. Example : One box would contain the tweets I liked, and another the tweets I retweeted.


Solution

  • You would need to create two separate stores in different directories. This can be accomplished using the directory parameter of openStore.

    _store1 = await openStore(directory: '/retweets');
    _store2 = await openStore(directory: '/likedTweets');
    

    Be aware that if you do this, you can't use relations between objects stored in separate stores using the built in relations. Ex: You couldn't have any of your retweeted objects use a relation to any liked tweets.

    To bypass that, you could use some unique ID to query the other store exactly like you would with a RDB