3

I have the following table schema:

db.version(1).stores({
    sales: "[item_id+date],sales"
});

Where the combination of date and item_id must be unique. How can I get all the records for a given item_id using the where clause (disregarding the date)?

The following produces an error:

db.sales.where('item_id').equals(some_item_id)

Unhandled rejection: SchemaError: KeyPath item_id on object store sales is not indexed

Yoav Kadosh
  • 4,807
  • 4
  • 39
  • 56

1 Answers1

2
db.sales.where('[item_id+date]').between ([some_item_id, -Infinity], [some_item_id, Dexie.maxKey])
David Fahlander
  • 5,058
  • 1
  • 20
  • 19
  • Thanks you. For some reason the above returns `n-1` records. Perhaps it is because `between` is non-inclusive? – Yoav Kadosh Sep 30 '16 at 00:20
  • OK, `between ([some_item_id, -Infinity], [some_item_id, Dexie.maxKey, true, true)` does it. – Yoav Kadosh Sep 30 '16 at 00:26
  • This just doesn't seem to work, I have executed the following query, `await window.db.Thread.where('[last_message_received_timestamp+needSync]').between([Dexie.minKey, 1], [Dexie.maxKey, 1]).toArray()` and it returns me the entire set of results. I have verified that there is not value in IDB with needSync = 1. I am using Chrome Latest version – Shubham Khatri Mar 03 '20 at 07:11
  • @ShubhamKhatri Dexie.minKey and Dexie.MaxKey must be the second position of the array. You put it in the first.' – David Fahlander Mar 04 '20 at 08:16