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

Adding unique emails #3

Open
theorye opened this issue Mar 27, 2017 · 3 comments
Open

Adding unique emails #3

theorye opened this issue Mar 27, 2017 · 3 comments

Comments

@theorye
Copy link
Owner

theorye commented Mar 27, 2017

ATM, there is nothing to ensure that emails are unique

Suggested code:

r.branch(r.table("users").getAll(email, {index: "email"}).isEmpty(),
         r.table("users").insert(user),
         {})
@genyded
Copy link

genyded commented Mar 27, 2017

That will work assuming the index is there, but should probably be combined with something that checks if the query contains {index: ...} and if so making sure the index exists with something like this before attempting to use the index:

 r.db('somedb').table('users').indexList().contains('email')
  .do(function (indexExists) {
    return r.branch(indexExists, { created: 0 }, r.db('somedb').table('users').indexCreate('email'))
  })

That of course has to be abstracted the way db and table are now in feathers-rethink to automate it.

@theorye
Copy link
Owner Author

theorye commented Mar 27, 2017

@genyded

Should I make this its own service or use hooks?

@genyded
Copy link

genyded commented Mar 27, 2017

I guess that depends on if you want it always, or sometimes. If always make it a hook that always runs. If sometimes, either it's own service that you can call it independently when needed, or a hook with an option to specify whether or not to run it for any given call. The real question is whether or not there would ever be any scenario where you might want to allow duplicates for any reason - even temporarily like maybe for a data merge or something.

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

No branches or pull requests

2 participants