mirror of
https://github.com/appy-one/acebase.git
synced 2026-05-24 22:01:13 -06:00
[GH-ISSUE #67] Indices with custom storage not working #50
Labels
No labels
IndexedDB
browser
bug
dependencies
documentation
duplicate
enhancement
feature request
indexes
indexes
invalid
pull-request
query
question
transaction logging
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/acebase#50
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @gryphonmyers on GitHub (Feb 5, 2022).
Original GitHub issue: https://github.com/appy-one/acebase/issues/67
Originally assigned to: @appy-one on GitHub.
I have written a custom storage class and it seems to be working just fine, except that if I try to create an index I get file access errors indicating it is trying to use non-custom storage for those operations, e.g.:
yields:
You can see it seems to be trying to open a .acebase file but there isn't one in this case. Is this a known issue? Am I doing something wrong?
@appy-one commented on GitHub (Feb 5, 2022):
Creating indexes should work for custom storage, the only requirement is that the filesystem is available. You are getting an error because the key to index contains a slash, which is not allowed.
I don't know what data you are trying to index, but your target doesn't seem right. If you want to index every
idof everysyschild of every root child (eg"/child1/sys/id","/child2/sys/id","/child34/sys/id"etc) I'm afraid that is not possible. The key to index cannot be a path, and the index path is expected to be a collection. To work around this limitation, you'd have to move theidto reside in the index path target:"/child1/sys_id","/child23/sys_id"etc and then create the index on"", "sys_id"- that will index"*/sys_id".I do wonder where the
[undefined]in the target file path originates from, I will check that out.I'm curious what type of custom storage you created, would you like to share?
@gryphonmyers commented on GitHub (Feb 5, 2022):
It doesn't work if I remove the slash either:
Error:
This is the storage class I'm using:
As an aside, that is unfortunate that the slash is unsupported because I'm working with a third party structure that put its primary keys in nested objects. This is the structure I am forced to work with. Note that it has the top level keys "metadata", "sys", "fields" and all data is stored under these (including the primary key
sys.id). Acebase should have adequate functionality to let me query this data, as you've already demonstrated, but the situation I'm trying to figure out now is how to resolve these entry links (see underfields.contentbelow - it's an object with an id but no reference to which collection it is referencing). This is why I was trying to create an index so I could do a wildcard query to find the referenced entry, but apparently that's not going to work out for me if indices can't be created on nested keys. Do you have any other suggestions for how I might accomplish this without modifying the structure (as I mentioned this is a structure coming from a third party tool and I'd like to preserve compatibility with it)?@appy-one commented on GitHub (Feb 6, 2022):
Thanks for the details, I see you created a cool in-memory storage class there!👌🏼
I'll have to dive into the indexing (and query) code to see if there is a way to implement nested key indexing. Implementing such a feature would obviously take some time. If you want me to prioritise this, please consider sponsoring me for my efforts! 😇
I will check out why it fails to create the index file for a custom storage class asap.
@appy-one commented on GitHub (Feb 20, 2022):
I think there is good news for you on the horizon! I changed parts of the code, looks like indexing and querying on subkeys will become possible...
@appy-one commented on GitHub (Feb 21, 2022):
I just published acebase version 1.15.0, The error should be gone and indexing on 'sys/id' possible:
await db.indexes.create('', 'sys/id'). Let me know if it all works!@gryphonmyers commented on GitHub (Feb 22, 2022):
Awesome! Will check it out
@gryphonmyers commented on GitHub (Feb 27, 2022):
@appy-one hmm so after updating to 1.15.1 things have changed a bit, but still not working for my use case. It now seems to be generating a testdb.acebase directory in the same directory as the script where I'm creating the index (before it was just complaining that the testdb.acebase file didn't exist, now it's actually creating it even though I'm using custom storage). After creating this directory with an index file within it, if I run my test a second time I get this error:
@appy-one commented on GitHub (Feb 28, 2022):
Yes, indexes are created on disk regardless of your custom storage implementation. If you'd switch to AceBase's default binary storage for your data, you can specify a path to store the files. Is there a particular reason you are using in-memory storage?
Looking at the error you are getting now, it sounds like the index file was not correctly written somehow. Did you get an error while executing
indexes.create?@appy-one commented on GitHub (Mar 19, 2022):
Can you give me an update on this?
@gryphonmyers commented on GitHub (Mar 30, 2022):
Sorry for the delay. I got routed to another project. Will look into this soon.
@gryphonmyers commented on GitHub (Apr 12, 2022):
No, no error is thrown there. If something is going wrong, it's not letting me know about it. I think I've accurately described the issue, and it is still happening with v1.16. This error is not thrown the first time I run the test, only on subsequent executions after the file has already been written.
I'm finding it odd that the custom storage functionality cannot customize the storage implementation for indices. What about scenarios where file persistence is not viable? We have no way to reliably persist our indices along with the rest of the data?
@appy-one commented on GitHub (May 9, 2022):
My apologies for the late reply. If you can provide code that reproduces this, I'll be able to check what might be going wrong.
Indexing is a feature that has nothing to do with the ability to create custom storage adapters for your data. An index is highly specialized to quickly deliver query results and not something you can just stick into any datastore for it to work. I'd be happy to build customization features that will allow you to handle index operations (create/remove/insert/update/delete/query etc) yourself, but this is not on my todo list. If you want it to be, consider sponsoring me!
I added other storage options to allow your data to be stored elsewhere, indexing was added later and works regardless of the used storage engine. I understand you'd prefer to store indexes along with the data, but it does not affect the reliability in any way. Your data and indexes are always only altered by AceBase, so they won't go out of sync.
@appy-one commented on GitHub (May 19, 2022):
Closing this for now, feel free to reopen or comment again later