1

I have an IDB with the following structure :

id: 1
name: "test"
operations: [
  {
    column: "active"
    operator: "="
    value: true
  }
]

Here the ID is added like so :

request.onupgradeneeded = e => {
            let db = e.target.result
            db.createObjectStore('filters', { autoIncrement : true, keyPath: 'id'})
        }

Users can either add a new record, in which case it will have id: 2 and so on, or add an operation to an existing record.

What should I do to add an auto incrementing key to each operations ?

Expected result :

id: 1
name: "test"
operations: [
  {
    id: 1
    column: "active"
    operator: "="
    value: true
  },
  {
    id: 2
    column: "age"
    operator: ">"
    value: 32
  },
]

1 Answer 1

1

IndexedDB won't help you with that, you'll have to handle it in your application code. Auto incrementing keys in IndexedDB are only for the primary key of the object.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ! I turned to uuid to fit my needs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.