- From: Ivan Artemiev <notifications@github.com>
- Date: Thu, 03 Nov 2022 11:27:28 -0700
- To: w3c/IndexedDB <IndexedDB@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/IndexedDB/issues/394@github.com>
I've noticed an IndexedDB implementation discrepancy between WebKit-based browsers and others (Chrome, FF, Opera) and would like to get clarification about which behavior is correct/expected. 
## Scenario
I have an index on my store with a key path list containing a **single** string:
```js
const store = db.createObjectStore("store")
store.createIndex("byIdArrayKey", ["id"]))
```
I insert a record into the store via `put`or `add`:
```js
store.put({
  id: 1,
  title: "hello",
  description: "this is a test"
})
```
## Discrepancy
On Chrome, FF, and Opera the index key that gets calculated from this value has type array and value `[1]`
On WebKit-based browsers the index key has type number and value `1`
The consequence of this difference in behavior is that when I go to retrieve the record from the index by key
Chrome, etc. expect an array key
```js
const getRequest = index.get([1])
getRequest.onsuccess = (event) => {
  console.log(event.target.result) // successfully retrieves the record {id: 1, title: "hello", ...}
}
```
But on WebKit-based browsers the result of this request is `undefined` and I need to query by the number key `index.get(1)` in order to retrieve the record.
Note: if the key path list on my index contains > 1 string such as `store.createIndex("byIdAndTitle", ["id", "title"]))` then WebKit will expect an array key when calling `get` on the index. The issue is only present when the key path list contains a single string.
## Question
Should an array key path always produce an array key?
Reading section [7.1](https://www.w3.org/TR/IndexedDB/#evaluate-a-key-path-on-a-value) of the IndexedDB spec, specifically
> 1 If keyPath is a [list](https://infra.spec.whatwg.org/#list) of strings, then:
>  1. Let result be a new [Array](https://tc39.github.io/ecma262/#sec-array-objects) object created as if by the expression [].
Seems to suggest that this is the case and that the WebKit implementation is incorrectly coercing the key to a scalar when the key path is a list containing a single value.
I would appreciate a definitive confirmation before I open a Bug Report with WebKit.
Thank you!
-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/IndexedDB/issues/394
You are receiving this because you are subscribed to this thread.
Message ID: <w3c/IndexedDB/issues/394@github.com>
Received on Thursday, 3 November 2022 18:27:40 UTC