You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When refactoring the project there were some considerations that lead to that decision.
Backwards compatibility - Version 1 of SleekDB already had that restriction, so changes to that functionality need to be done well and backwards compatible.
Ease of use and implementation - Currently SleekDB internally increase a numeric counter by one for every "storing operation" to generate a unique id.
Consistency and abstraction - A half baked implementation could lead to inconsistent code and behaviour.
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.
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.
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 :)
Hi. I landed here because of the error I recieved as I tried to use my own primary key:
Fatal error: Uncaught SleekDB\Exceptions\InvalidArgumentException: **The id of the document has to be numeric** in /SleekDB/Store.php:883 Stack trace: #0 /SleekDB/Store.php(384): SleekDB\Store->checkAndStripId('test1') #1 some.php(102): SleekDB\Store->updateOrInsertMany(Array, false) #2 {main} thrown in /SleekDB/Store.php on line 883
I configured the database with '"primary_key" => "url"', and tried to use $results = $contentStore->updateOrInsertMany($content, false);.
I did this because in the documentation under primary key it is written:
#Set the primary key into any string you want.
#SleekDB will then use that key instead of the default _id key.
To mee this looks as it is not supported (but I just started using SleekDB, so high probability of me understanding something wrong. Also: Thanks for your work!)
Activity
Timu57 commentedon 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.
ramsey/uuidWe 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()andupdateOrInsertMany()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
_idgeneration 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 commentedon Jul 31, 2022
Hi @Timu57,
I certainly don't wat to introduce
ramsey/uuidas 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 :)CJS-Design commentedon Jan 2, 2025
Hi. I landed here because of the error I recieved as I tried to use my own primary key:
Fatal error: Uncaught SleekDB\Exceptions\InvalidArgumentException: **The id of the document has to be numeric** in /SleekDB/Store.php:883 Stack trace: #0 /SleekDB/Store.php(384): SleekDB\Store->checkAndStripId('test1') #1 some.php(102): SleekDB\Store->updateOrInsertMany(Array, false) #2 {main} thrown in /SleekDB/Store.php on line 883I configured the database with '"primary_key" => "url"', and tried to use
$results = $contentStore->updateOrInsertMany($content, false);.I did this because in the documentation under primary key it is written:
#Set the primary key into any string you want.
#SleekDB will then use that key instead of the default _id key.
See: https://sleekdb.github.io/#/configurations#primary_key
To mee this looks as it is not supported (but I just started using SleekDB, so high probability of me understanding something wrong. Also: Thanks for your work!)