Skip to content

@Unique: replace on conflict flag #297

@dimzeta

Description

@dimzeta

I am new to Objectbox, but it seems to fit to my needs, except for one thing: upsert data.
I fetch some items to my API server (300 items) and they have a UUID, with @unique. Sometimes, these items are updated and I would like to fetch/update them, by their UUID.

FYI this is what I'm doing currently, I don't know if it's the best way:

List<CardModel> cards;

cards.forEach((card) {
        card.extension.target = extension;

        CardModel? cardInDb = _cardRepository.findByUuid(card.uuid);

        if (cardInDb != null) {
          card.id = cardInDb.id;
        }
});

_cardRepository.box.putMany(cards);

After some researches, I've seen that Objectbox Java has a OnConflict flag for @unique:

@Unique(onConflict = ConflictStrategy.REPLACE)
See objectbox/objectbox-java#509

It would be great if we have the same thing in Dart/Flutter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions