Skip to content

Recursively remove/clear items #638

@Niki2k1

Description

@Niki2k1

Describe the feature

Feature Request

It would be very nice to recursively delete/clear sub-items in a storage.

Expected Behavior

We have a users base like this where we set an array of users for e.g caching.

await useStorage('cache').setItem('users:all', '[{ ... }]')
await useStorage('cache').setItem('users:admin', '[{ ... }]')

Now I want to be able to remove the prefix "users" which should recursively remove all items under the key.

await useStorage('cache').remove('users')
// or
await useStorage('cache').clear('users')

Clear which gets described in the Documentation as

Removes all stored key/values. If a base is provided, only mounts matching base will be cleared.

Which to my understanding should exactly be what I am search for, but with a fs driver it does not work (maybe a bug? I can provide a reproduction if needed)

If its not a bug:
Should I just use a loop with getKeys() and removeItem() or is there a better way it could be supported directly in unstorage.

Thank you! 💛

Maybe I don't understand bases correctly. My mental model is only wrapped around the file system implementation but redis for example does not have folders and the key is just a string and you probably can't say remove items with users:* (?)

Reproduction

https://stackblitz.com/edit/github-58uuvdlj?file=server%2Froutes%2Findex.ts

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions