Skip to content

Suggested pattern for usage with Dexie (or IndexedDB) #98

@dskvr

Description

@dskvr

Does anyone have experience or an example to share of how to implement @square/svelte-store on an IndexedDB that has multiple tables and indices?

From what I can gather, to implement IndexedDB using this library, one would not just create an INDEXED_DB StorageType but rather a StorageType for each individual table. Additionally, due to the restrictive interface of the getter/setter/deleter functions, if there were multiple indices, there would need to be a StorageType for each desired index within a table. TABLE1_KEYPATH1 ... TABLE1_KEYPATH2 ... etc, which other than having some maintenance issues, would likely face some performance issues as well (potential for duplicate, dereferenced data)

For example with Dexie, where a "key" can be a object

Interface for Table.get()

table.get(primaryKey): Promise
table.get({keyPath1: value1, keyPath2: value2, ...}): Promise

From what I can see, this is not compatible with the existing interfaces of getStorageItem/setStorageItem/deleteStorageItem, forcing what might be considered an anti-pattern on an implementation (storage types for each index as mentioned above, or wrap this library to JSON.stringify arguments and then JSON.parse the arguments in the functions)

Please let me know if I am missing something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions