The Wayback Machine - https://web.archive.org/web/20210107201148/https://github.com/dfahlander/Dexie.js/issues/1123
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to add onto the current database using 'dexie-export-import' module? #1123

Open
IcyFoxe opened this issue Sep 14, 2020 · 12 comments
Open

Comments

@IcyFoxe
Copy link

@IcyFoxe IcyFoxe commented Sep 14, 2020

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.

@dfahlander
Copy link
Owner

@dfahlander dfahlander commented Sep 14, 2020

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.

@dfahlander
Copy link
Owner

@dfahlander dfahlander commented Sep 14, 2020

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.

@IcyFoxe
Copy link
Author

@IcyFoxe IcyFoxe commented Sep 14, 2020

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?

@IcyFoxe
Copy link
Author

@IcyFoxe IcyFoxe commented Sep 14, 2020

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...

@dfahlander
Copy link
Owner

@dfahlander dfahlander commented Sep 15, 2020

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?

@IcyFoxe
Copy link
Author

@IcyFoxe IcyFoxe commented Sep 15, 2020

Yes. Exactly that. :)
I'm working on a site using your awesome Dexie.js module, and I will need a feature that could do that.

I've noticed, that if I remove all the ids from the JSON file, it will generate new ids on its own.

@dfahlander
Copy link
Owner

@dfahlander dfahlander commented Sep 15, 2020

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()

@IcyFoxe
Copy link
Author

@IcyFoxe IcyFoxe commented Sep 15, 2020

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:
https://i.imgur.com/atPDlW5.png

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..

@dfahlander
Copy link
Owner

@dfahlander dfahlander commented Sep 15, 2020

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().

@IcyFoxe
Copy link
Author

@IcyFoxe IcyFoxe commented Sep 15, 2020

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?

@dfahlander
Copy link
Owner

@dfahlander dfahlander commented Sep 15, 2020

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.
Pull request would be welcome!

@IcyFoxe
Copy link
Author

@IcyFoxe IcyFoxe commented Sep 15, 2020

Yeah, that would be a perfect solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.