Skip to content
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

Any easy way to create multi-field indexes, not just single field? #24

Closed
mariusk opened this issue Mar 5, 2015 · 10 comments
Closed

Any easy way to create multi-field indexes, not just single field? #24

mariusk opened this issue Mar 5, 2015 · 10 comments
Labels

Comments

@mariusk
Copy link

mariusk commented Mar 5, 2015

No description provided.

@alekseykulikov
Copy link
Contributor

Treo supports multi as a part of addIndex: https://github.com/alekseykulikov/treo#schemaaddindexname-field-opts

var treo = require('treo');
var schema = treo.schema()
.version(1)
  .addStore('magazines', { key: 'id' })
  .addIndex('byWords', 'words', { multi: true });

Is it what you need?

@mariusk
Copy link
Author

mariusk commented Mar 6, 2015

I do not think so. I'm under the (possibly wrong) impression that indexeddb allows indexes based on multiple field values, not just a named array field.

@alekseykulikov
Copy link
Contributor

Ah, probably you mean something like: http://stackoverflow.com/a/16503172

schema.addIndex('compoundIndex', ['field1', 'field2']);

Currently treo does not allow to do this, because it expects string as a key field: https://github.com/alekseykulikov/treo/blob/master/lib/schema.js#L90
Also probably ranges will not work too.

I will mark it as a feature for next release.

@mariusk
Copy link
Author

mariusk commented Mar 8, 2015

Another thing to add to the feature list might be an easy way to call .all on an index or similar, to iterate by a certain index. Alternatively, add interfaces (or document) how to access the underlying cursors to do it.

@alekseykulikov
Copy link
Contributor

Yes, support of ranges in store.all could be a good addition.
Internal store.cursor is also available, but has weak docs. So far as example you can check: https://github.com/alekseykulikov/treo/blob/master/examples/find-in-plugin.js

@robertfall
Copy link

We've just run into this issue. Is there a way to drop down to raw indexeddb to add the index with multiple fields until it's been added to treo? 😕

@alekseykulikov
Copy link
Contributor

treo@0.5.0 adds support for this functionality.

@lukerandall
Copy link

Thanks for the quick response. Much appreciated!

@robertfall
Copy link

Indeed! Didn't expect this to land so soon. Thanks for your work! 👍

@alekseykulikov
Copy link
Contributor

You're welcome, guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants