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

Enforce unique for keys #4

Closed
skoshx opened this issue Jun 7, 2023 · 5 comments
Closed

Enforce unique for keys #4

skoshx opened this issue Jun 7, 2023 · 5 comments

Comments

@skoshx
Copy link
Owner

skoshx commented Jun 7, 2023

No description provided.

@lilnasy
Copy link
Contributor

lilnasy commented Jun 15, 2023

What do you mean by this?

@skoshx
Copy link
Owner Author

skoshx commented Jun 16, 2023

@lilnasy This is basically when we mark keys as unique with the .describe("unique"), so if we have a schema like

{
  id: z.string().uuid().describe("primary, unique"),
  email: z.string().describe("unique")
}

We need to enforce that we're not allowed to create any items with existing values or update any items that break the unique constraints

@jnssnmrcs
Copy link
Contributor

what's your definition of index and unique here? because it seems like properties with index attribute are treated as unique indexes in the code at the moment.

@skoshx
Copy link
Owner Author

skoshx commented Jun 25, 2023

@jnssnmrcs index is meant to be used to do secondary indexing so for instance index by email key, but now that you mention it, yeah, index is treated basically as unique indexes, which is wrong I think?

You bring up a good point in the implementation of the secondary key indexing, not sure how it should be implemented so that an indexed key doesn't have to be unique, without adding too much extra complexity to the implementation...

Edit: Will open a new issue for this

@jnssnmrcs
Copy link
Contributor

jnssnmrcs commented Jun 25, 2023

Yea I think treating all indexes as unique is wrong. I was just reading up about the differences and came across this answer on stackoverflow which explained how it works in MySQL: https://stackoverflow.com/a/708508/8952488

It also feels superfluous to say that a primary is also unique (like you do in most examples), since a primary index is always unique.

@skoshx skoshx closed this as completed in b5f59e1 Jul 4, 2023
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

3 participants