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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get all of a kind #3
Comments
Hello! That is not possible, by design, since a namespace doesn't restrict the type of items, it simply adds an extra component to the key of the item. Given that, if we try to retrieve all items, it won't be type safe anymore. Can you please share more about your use case? I can help you figure out a better way to use this library, hopefully, or we can come up with a new feature that accommodates your needs. (On the other hand, if you want to look at other established key value stores, like redis, you will see they don't allow fetching all items in a namespace, because that is more like a query, which is better accommodated by a database) |
Hi! Thanks for your fast response! I'm storing model instances by their id using the namespace I copied on my question. I need now to fetch all of them to populate a table view. It's a small app and there won't be more than 15 items stores under the namespace. I wanted to avoid incurring into the work of using a relational database for it. I'm thinking a possible workaround for this could be storing an array of all stored item keys under a certain key (for example, lists:all) and update it using the existing hooks on the ListsNamespace. |
Makes sense. You can definitely do that, or ... Check this out: struct ListsNamespace: Namespace {
static let id = "lists"
static let all: [Key] = {
return (0..<15).map {
Key<ListsNamespace, String?>(id: "\($0)", defaultValue: nil)
}
}()
}
store.set(ListsNamespace.all[0], value: "1")
store.get(ListsNamespace.all[0]) // "1" It might be easy to forget that I hope this helps .. It is also making me wonder if there is value of adding support to In all cases, please keep the feedback coming! |
Hi there!
How can I get all items stored under a certain Namespace? For example, I have the following namespace:
and I want to fetch all 'List' items.
Thanks!
The text was updated successfully, but these errors were encountered: