Best Way To Handle Checking For Duplicate Registrations #3719
-
I have an app that saves a Spotify access token to the DB when the user registered, and also gets a user_id from spotify. I have no passwords or usernames/email auths, I just store the access token and refresh token. I want to check if the user is already registered before adding a new access token to the table "Tokens". Currently I am doing:
This will jump to the catch block and add the new user. This smells very anti-pattern as I am using errors as control flow. Is there a better way of doing this? In head the way it would work would be if no row is found, record would be an empty object, but it does not seem to work like that. Maybe I am missing crucial sqlite experience? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Beta Was this translation helpful? Give feedback.
If all you want is a unique field validation then you can create a unique index for your field.
This can be done from the Admin UI > Collections > Edit collection panel under the "Unique constraints and indexes" section: