LokiDB icon indicating copy to clipboard operation
LokiDB copied to clipboard

Add option to indexedDB to store object instead of string

Open Viatorus opened this issue 7 years ago • 2 comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/LokiJS-Forge/LokiDB/blob/master/CONTRIBUTING.md#question

Current behavior

IndexedDB stores the database as a JSON string.

Expected behavior

IndexedDB stores the database as an object. Can be enabled via an option.

What is the motivation/use case for changing the behavior?

IndexedDB is an object storage so it can store hole objects (including Date, Map, Blobs etc.). This would decrease storage space because e.g. Blobs don't have to be serialized using base64.

Viatorus avatar Oct 28 '18 11:10 Viatorus

Hey @Viatorus, sorry I've been out of GitHub loop for a while... hope to get back up to speed soon.

If I recall correctly, I tried that once but it ends up doing a serialization itself (in native code) and I think it was having trouble with our serialize replacers (since those are scoped to js).

It might still be usable in situations where we store data separately from loki (database) and collections... in partitioned situations. Maybe faster as well.

obeliskos avatar Nov 10 '18 15:11 obeliskos

Hey @obeliskos, no problem. I am also not that active. ;)

Interesting for me is the handling of blobs and TypedArrays independent of the used storage (localStorage, IndexedDB, fs, ...). So we would need another serialization approach than stringifying.

The package https://github.com/localForage/localForage seems to does this by the way.

Viatorus avatar Nov 12 '18 10:11 Viatorus