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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can save() be used as an update? #63

Open
Eyesonly88 opened this issue Dec 29, 2016 · 5 comments
Open

Can save() be used as an update? #63

Eyesonly88 opened this issue Dec 29, 2016 · 5 comments

Comments

@Eyesonly88
Copy link

Eyesonly88 commented Dec 29, 2016

First of all, thank you very much for your amazing library 馃憤

I've got a question regarding using the save() operation. In my use case, I'm saving by key and the key is the date. I want to update the rawData without overriding the existing data.

For example:

// first save operation
...
rawData: [ { car: 'tesla' } ]
...

// second save operation
...
rawData: [ { car: 'mazda' } ]
...

// Now doing a load on key, I want to get
[ { car: 'tesla' }, { car: 'mazda' } ]

// but I actually get
[ { car: 'mazda' } ]

Is that possible to do currently? or do you recommend a way of achieving this?

One way I thought I can do it is by doing a load of the data first, then appending it manually, then storing it back.

Also as a side note, my keys have numbers in them and it seems to work (you mentioned underscores are not permitted), so I'm guessing using numbers in keys is supported ?

@sunnylqm
Copy link
Owner

Currently "update/merge" operation is not yet supported, but it's easy to implement by yourself.
You can do a load and then use Object.assign to merge data and then save, or maybe you can split a list into key-id data.
I'll consider to add this update() feature when I have spare time. And of course PR is highly welcomed.

@Eyesonly88
Copy link
Author

Thanks for the quick response.
Yep, I just implemented update like you said 馃憤 . I used the spread operator.

Just to confirm, is having a number in the key supported?

@sunnylqm
Copy link
Owner

You can have number in the key, just not use pure number cause it's really confusing and error-prune.

@Eyesonly88
Copy link
Author

Awesome thanks 馃憤. Yep my 馃攽 looks like this ThuDec292016

@bosz
Copy link

bosz commented Aug 6, 2018

Learnt much from the chat. Thanks @Eyesonly88 and @sunnylqm . I think this issue can be closed, maybe a label "recommendation" added to it right so that it gives way for other issues 馃槃

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