Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique properties #20

Closed
kordianbruck opened this issue Jan 28, 2017 · 25 comments
Closed

Unique properties #20

kordianbruck opened this issue Jan 28, 2017 · 25 comments
Labels
enhancement New feature or request
Milestone

Comments

@kordianbruck
Copy link

kordianbruck commented Jan 28, 2017

It would be great to have unique annotation so that a put operation can detect, that this row is already existing and needs to be updated instead of creating a new one.

I know this is possible already by making it the @id column and assignable, but sometimes one needs multiple unique columns.

Also this would allow to have different types of keys as one could possibly also use a string.

@greenrobot greenrobot added the enhancement New feature or request label Jan 28, 2017
@greenrobot greenrobot added this to the 0.9.x milestone Jan 28, 2017
@greenrobot greenrobot removed this from the 0.9.x milestone Jul 21, 2017
@greenrobot
Copy link
Member

Will revisit shortly after 1.0

@Mistic92
Copy link

Would be great. I'm getting user ids from backend as Strings and for now I have to check if user exists manually.

@lucassales2
Copy link

Any updates on this feature?

@Mistic92
Copy link

Mistic92 commented Oct 8, 2017

Any news?

@greenrobot
Copy link
Member

To plan this a bit better, we have some questions (the more answers from different people the better...):

  1. For string uniqueness, is it always OK to have case-sensitive uniqueness?
  2. For unique string, would you plan to have "starts with" on it?

There are some design decisions depending on that.

@DJafari
Copy link

DJafari commented Oct 8, 2017

  1. i think it must be optionable, it's mean sometimes we want case-sensitive uniqueness sometimes no
  2. i think this is should be optionable, in some case starts with is good, but in other case no
@Unique(caseSensitive = true, starsWith = false)
public String title

@Mistic92
Copy link

Mistic92 commented Oct 8, 2017

  1. For me it's ok. I need unique field or String as id for Datastore id's which I'm getting from backend.
    They looks like this "005e32a2-2dd3-4571-bcfe-019a009564f0".
  2. Nope

@Ekalips
Copy link

Ekalips commented Oct 8, 2017

As for me:

  1. Would be nice if it will be optional. With true as default. But if it'll over complicate system then better to have always case sensitive.
  2. Not really

@lucassales2
Copy link

1-) I think it can solve most my problems for sure, but in some rare cases it may be a problem.
2-) No. String ID is normally gererated because the API does not want to expose it's real ID, in all of my cases it wont mather

@thangmam
Copy link

I agree with @DJafari .Although i do not know how it would impact the designs ,it would be nice to have that kind of freedom to choose.

@silviahisham
Copy link

  1. I think it's ok, but would be better if it's optional.
  2. Nope

@wheelerruss
Copy link

  1. case sensitive would be fine as I would like to use Ids such as "abskBD7Sndm65Snc"
  2. I have no need for this that I can think of.

Can I just confirm, that currently, if I have a Box with a String field that I would like to use as the unique ID, in order to do insert or update statements, I'll need to do a quick query first to see if the row exists?

@Mistic92
Copy link

@wheelerruss yep, I didn't found any other way. That's why if I have any relation I have to check and create every entity by myself because when objectbox do it I have a lot of duplicates.

@wheelerruss
Copy link

Yeah that makes sense. But fingers crossed this isn't too far away from being finished :D

@motis10
Copy link

motis10 commented Nov 19, 2017

Any news with this issue?

@greenrobot
Copy link
Member

50% done. We're using a new kind of index (hash indexes) for this.

@AllenCoder
Copy link

Very looking forward to the unique attribute, when released?

@AllenCoder
Copy link

When can this feature be released ?

@Mistic92
Copy link

Any update? ;)

@chrbongardt
Copy link

chrbongardt commented Jun 28, 2018

Hi, is there any news regarding this feature?

@Mistic92
Copy link

As i saw it will be in objectbox 2.0 when it hit GA. Now it's in beta

@greenrobot greenrobot added this to the 2.0 milestone Jul 17, 2018
@avcial
Copy link

avcial commented Jul 25, 2018

All requirement for @unique annotation is for the same usability of SQLite insert queries SQLiteDatabase.CONFLICT_REPLACE option, developers usually uses mobil databases for cache datas to improve response time for queries and they don't want to give their live ObjectId's from server databases, they ussually use GUID's which aren't supported exactly as UUID's but can be stored as Strings in mobil databases.
So Annotation must have options for inserting strategy ;
Should it replace it or it should ignore this row for insert query

But i think the best approach must be that @uniq annotated fields must be considered as PrimaryKey's which can be given or which can be generated automatically if not specified

@greenrobot
Copy link
Member

2.0.0 released with @Unique.

Opened #509 for "replace on conflict" - if you require it, please give a thumbs up reaction on the new issue.

@kordianbruck
Copy link
Author

@greenrobot pretty please for a github release/tag? 💯

@greenrobot
Copy link
Member

@kordianbruck Here you go: https://github.com/objectbox/objectbox-java/releases/tag/V2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests