Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

How to Export / Import database #1012

Open batuhansahan opened 3 years ago

batuhansahan commented 3 years ago

Is there a way to export / import(restore) database.

mk1020 commented 3 years ago

do you guys have any ideas?

de1mat commented 3 years ago

Also interested

przbadu commented 2 years ago

Using RNFS, you can copy your DB file to preferred path. Tested in android.

  const localDBFilePath = '/data/data/<package-id>/watermelon.db';
  const databaseBackupFilePath =  `${RNFS.DownloadDirectoryPath}/backup.db`;
  await RNFS.copyFile(this.localDBFilePath, databaseBackupFilePath);
SachinCoder1 commented 2 years ago

Hi, is anyone working on it? i am new to open source, how do i get started?

heyalexchoi commented 2 years ago

Using RNFS, you can copy your DB file to preferred path. Tested in android.

  const localDBFilePath = '/data/data/<package-id>/watermelon.db';
  const databaseBackupFilePath =  `${RNFS.DownloadDirectoryPath}/backup.db`;
  await RNFS.copyFile(this.localDBFilePath, databaseBackupFilePath);

This doesn't work. The copied files won't necessarily be the same or reflect what's happening in memory.

Currently looking at how to best do this. FMDB (the sqlite objective-c wrapper that watermelondb uses) actually has a function to accomplish this loadOrSaveDb but the FMDB embedded in watermelondb doesn't have it and hasn't been updated since 2018.

I will probably fork, add that file, and expose to js to allow proper backup / restore on iOS. @radex and whoever is maintaining, please let me know if you have any thoughts on that. This is a robust project and obviously I'd like to get a PR merged and not stay on a fork.

alicja-mruk commented 2 years ago

any updates?