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
Add upserts #158
Comments
thanks for this! Upserts are in fact underway for 1.4 - mechanism is very similar to the one you outlined so it should be to your satisfaction. |
Thanks! 👍 |
Leaving this open till its implemented. Cheers |
@techfort this is actually what I wrote the
|
@retorquere that looks like perfectly sound logic, and the final code will probably be just a port to js of it. Thanks! |
If update will return its subject at some point, it would become even shorter:
for upsert, you'd probably want to do something like (actual coffeescript, just easier for me to write)
without unique constraints, and doesn't cause updates unless actual changes are made
|
thanks a lot for this @retorquere ! |
+1, this will be very handy to have :) |
Worth nothing that the |
v1.4.1 has been released on 5 July 2016, but it seems to lack upserts. Any updates on this? |
By any chance is there some progress with this? |
Any Updates on this? |
Any Updates? We really need this functionality. |
I will track it for LokiJS2. |
Hi, is there any ETA for this? @Viatorus |
Yes, I tracked it for LokiJS2 but there are still some other work to do. But this could be one of the first features after the first release of v2. |
|
Is this feature available for 2017 Christmas? Or the Nordic gods don't like it? |
Does anyone want to create a pr for this? We are in a maintenance mode for this branch but this feature should be isolated and somewhat limited in scope. (Typically LokiJS2 will be where most new feature requests go) If anyone wants to have a go at it on this repo, please use ecma 5 standards and provide a unit test. I would expect this could be done with :
I think that would do it, if anyone sees I missed anything feel free to point that out. |
Is there a LokiJS2 roadmap btw? Will the serialization formats remain the same (thinking migration issues here)? |
@obeliskos This should probably do it. But the idField is obsolete or not enough. What happen if someone has multiple unique constraints? The function upsert have to check if either the 'doc' fulfills all unique constraints with an existing document in the collection, if not try to insert (maybe violates the constraint and throws). @retorquere No, LokiJS2 is not compatible right away. But an extra database-migration-tool script could be possible. You find the beta of LokiJS2 here: https://github.com/LokiJS-Forge/LokiJS2 |
Sorry I didn't read or respond a month ago... all valid points. All inserts/updates should go through collection.insert() and collection.update() to ensure any changes affecting indices are processed in one place. Detection and utilization of unique indices (via by()) would be for ensuring optimal lookup of individual doc(s) and if passed properties modify indexed fields, the call to update() should reintegrate within indices. I think that covers danger areas but it would need unit tests to fully define and be sure. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
What's the recommended way to do upsert now with the latest loki version? 1.5.7? |
What's the recommended way to do upsert now with the latest loki version? |
Any update on this? |
Upserts would be nice, and it sounds from #79 like they're on the way.
I'm not good enough with JS to attempt a patch, but I can share a snippet I'm using to do upserts if anyone wants to use it until LokiJS has them baked in.
I can't guarantee how fast or robust it is, but it's working for me.
Note that it requires lodash.
The text was updated successfully, but these errors were encountered: