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

Support for unique columns #728

Closed
privatenumber opened this issue Jul 24, 2018 · 4 comments
Closed

Support for unique columns #728

privatenumber opened this issue Jul 24, 2018 · 4 comments

Comments

@privatenumber
Copy link

Case

Feature request

Request

I understand a pre hook can be made but would be nice if there is a unique: true or a compound unique array in the schema.

@privatenumber
Copy link
Author

Can work on a PR if feature request is approved.

@pubkey
Copy link
Owner

pubkey commented Jul 31, 2018

Hi @hirokiosame
The problem with unique fields is that we have a distributed database which can, or cannot be in sync with other instances.
This makes it very hard to enforce unique fields. For example if you use a unique value in document A and after some time you go online and sync again with a couchdb-server, it may happen that there is a document B with the same value.

There is this good proposal on stackoverflow on how to enforce unique fields and produce a conflict which can be handled if the same value is used.

I do not think there is a good way to generally solve this, so just creating a unique: true-flag and check the local instance if there is a other doc with that value, will give a wrong impression of security.

@privatenumber
Copy link
Author

Interesting case. Thanks for the info.

So, even adding a hook to pre-insert to check if the row already exists wouldn't cut it huh?

Is it possible to implement a soft-unique feature with the caveat of not being unique when the database is configured to sync? In my case, I am not syncing my rxdb instance.

@pubkey
Copy link
Owner

pubkey commented Aug 20, 2018

@hirokiosame
I will not add a misleading feature to rxdb. If you know that you do not use the replication, add a preInsert hook that checks for this.
You can always add own field to the schema and therefore just add a unique field, parse it and run the check inside of the hook. Please do not forget to use a proper index, otherwise it will slow down your massively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants