Skip to content

Make writes non-destructive#2

Merged
msiemens merged 2 commits intomsiemens:masterfrom
steinbro:master
Jan 4, 2016
Merged

Make writes non-destructive#2
msiemens merged 2 commits intomsiemens:masterfrom
steinbro:master

Conversation

@steinbro
Copy link
Copy Markdown
Contributor

I noticed, while working on recipy, that calling db.insert(data) on a dict with the DateTimeSerializer enabled will change data in-place, replacing each datetime with the serialized string. My fix is to do a deepcopy of the data dict as the first step of write. Not the most efficient, but it does the trick.

@msiemens
Copy link
Copy Markdown
Owner

msiemens commented Jan 4, 2016

calling db.insert(data) on a dict with the DateTimeSerializer enabled will change data in-place, replacing each datetime with the serialized string

That's a good point. It's definitely something we should fix.

My fix is to do a deepcopy of the data dict as the first step of write. Not the most efficient, but it does the trick.

I thought about it and the only alternative I could come up with was using persistent data structures. That would require us to rely on an external library like pyrsistent and incur some performance penalty on it's own, but would allow us to avoid creating a 2nd copy of all data. What do you think about this?

@steinbro
Copy link
Copy Markdown
Contributor Author

steinbro commented Jan 4, 2016

It'd be ideal to avoid external dependencies -- that's one of the goals of TinyDB, right? I just tweaked the patch to implement copy-on-write, so we're saved the deepcopy when the serializers don't apply.

@msiemens
Copy link
Copy Markdown
Owner

msiemens commented Jan 4, 2016

It'd be ideal to avoid external dependencies -- that's one of the goals of TinyDB, right?

That were my concerns, too. If anyone runs into performance troubles because of the copying, one can fork this project and adapt it accordingly. I'll go with your PR.

msiemens added a commit that referenced this pull request Jan 4, 2016
Make writes non-destructive
@msiemens msiemens merged commit a3db139 into msiemens:master Jan 4, 2016
@msiemens
Copy link
Copy Markdown
Owner

msiemens commented Jan 4, 2016

A new version of tinydb-serialization is now being uploaded to PyPI :)

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

Successfully merging this pull request may close these issues.

2 participants