Is there a way to add onto the current database using 'dexie-export-import' module? #1123
Comments
The option overwriteValues implies that the import uses bulkPut() instead of bulkAdd() - which means that new ids will be added and existing ones will be replaced. |
The docs of the addon could really be improved. Any help with that is of course always appreciated. Just use the edit button at https://dexie.org/docs/ExportImport/dexie-export-import and it will generate a github PR for the docs repo. |
Yeah, but neither of these do what I'm looking for. Let's say that I have a table that has fields with ids 1 - 25 and I want to import a json file, that has fields with ids 1 - 15. After importing, I want to have a table with ids 1 - 40 (old and imported fields combined). How can I do that? |
If there was an option for dexie-export-import module to ignore imported ids when using bulkAdd or bulkPut(), that would achieve what I'm looking for... |
Not sure how id 1-15 would be come 26-40? Are you looking for a feature that would generate new ids for the imported rows? |
Yes. Exactly that. :) I've noticed, that if I remove all the ids from the JSON file, it will generate new ids on its own. |
Aha! That's a thing I havent't thought of, but natural according to how IDB put and add works. I still don't see what you are after then? Do you want to merge the fields of the objects in case the import file has id that corresponds to existing id, but generate new ids in case the import file object lacks it? Or do you want dexie-export-import to go through your JSON file and remove each id property? Just trying to understand. If so, could you not mangle the json before sending it into importInto() / db.import() |
Since I'm not a native English speaker and it's rather difficult for me to describe what I mean, so I will explain it visually: What I'm looking for is only the "requested feature" - to be able to combine to add to the current database when importing. Optional features is something, that could possibly be implemented at the same time, with the main feature - to be able to select which fields to import, and which to ignore.. |
I see what you're after. However, my direct response would be that this feature is a bit too niche for this general addon, I think. It seems you could equally well achieve all requested features by just altering the json before calling db.import() / importInto(). |
Hmm, I guess that's possible.. However wouldn't the JSON alteration have to happen entirely in the memory? What if the JSON file is too big? |
If that's a real scenario in your use case, that could be an issue, yes. What I could accept would be a generic ImportOption to pass a function that could alter a row on inport - similar to the filter option but return an altered row instead of a boolean. |
Yeah, that would be a perfect solution! |
I read the docs of dexie-export-import thoroughly, however I didn't find a way how to add onto the current database when importing the data. It either completely replaces the whole table or merges and overwrites any row with the same id.
What I'd like to do is to import the data with new id's, while keeping the old data in the table intact.
The text was updated successfully, but these errors were encountered: