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

Allow to use UUIDs as primary keys #239

Open
robiningelbrecht opened this issue Jul 29, 2022 · 2 comments
Open

Allow to use UUIDs as primary keys #239

robiningelbrecht opened this issue Jul 29, 2022 · 2 comments
Labels
discussion feature question Further information is requested

Comments

@robiningelbrecht
Copy link

At this moment in time primary keys have to ne numeric:

The id of the document has to be numeric

I like to use https://github.com/ramsey/uuid to generate UUIDs for my entities, but I'm not able to use them as my primary key because they are not numeric. Is there a reason why there's such a restriction?

@Timu57 Timu57 added question Further information is requested discussion feature labels Jul 29, 2022
@Timu57
Copy link
Member

Timu57 commented Jul 29, 2022

Hi @robiningelbrecht

Thank you for your interest and feature request.

When refactoring the project there were some considerations that lead to that decision.

  1. Backwards compatibility - Version 1 of SleekDB already had that restriction, so changes to that functionality need to be done well and backwards compatible.
  2. Ease of use and implementation - Currently SleekDB internally increase a numeric counter by one for every "storing operation" to generate a unique id.
  3. Consistency and abstraction - A half baked implementation could lead to inconsistent code and behaviour.
  4. Additional Dependency - We try to avoid any kind of dependency. That's why we could offer a kind of API to hook into the standard behaviour but can't provide additional methods like with implementing ramsey/uuid

We thought about implementing a "string id" feature but didn't have the time to do so.

That said, If I remember correctly you can use the updateOrInsert() and updateOrInsertMany() methods to insert documents with your own ID.

https://sleekdb.github.io/#/insert-data#updateOrInsert

If you want to implement that feature you are welcome to do so 😊

The _id generation is already encapsulated into a single method.
https://github.com/rakibtg/SleekDB/blob/ecbf9224d7dd6214bce76da1dae8bcbd583e464e/src/Store.php#L837

You could extract that into it's own class and allow the user to implement their own functionality by providing a closure, custom class using an interface or something like that as a configuration option when creating a Store-Object.

Feel free to join our discord server if you need help or want to discuss details.

@robiningelbrecht
Copy link
Author

Hi @Timu57,

I certainly don't wat to introduce ramsey/uuid as a dependency in the codebase. I was just wondering why strings are not supported as primary keys. I'll join the Discord server to discuss this PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion feature question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants