jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.22k stars 348 forks source link

TypeScript: special case for auto-incrementing primary keys, v2 #252

Open dumbmatter opened 2 years ago

dumbmatter commented 2 years ago

This is an improved version of #151, aimed at solving #150.

The general idea is that you specify the auto-incrementing key's name in DBSchemaValue["autoIncrementKeyPath"], and then internally it labels that property as optional when accepting new records in add and put. It even works with nested keys like "my.nested.id".

As a bonus, when autoIncrementKeyPath is set, createObjectStore now knows what to expect in its 2nd parameter - that it must have an auto incrementing key of the same name. This will help catch some typos.

The only caveat is I'm not sure how to make the 2nd parameter of createObjectStore optional if and only if autoIncrementKeyPath is undefined. See the comment I left in there.

megagames-me commented 3 months ago

Hi @jakearchibald, any updates on this getting merged or resolving #150? Thanks