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 it possible to backup, and restore database? #99
Comments
Nope, you'll have to build it. But it would be a nice thing to have. Either to string or to a Blob so you could handle large backups. A sample of how to write an export of all tables: function exportDatabase(db) {
return db.transaction('r', db.tables, function() {
// Map to transaction-bound table instances because instances in db.tables are not bound
// to current transaction by default (may change in future versions of Dexie)
var tables = db.tables.map(function (t) {
return Dexie.currentTransaction.tables[t.name];
});
// Prepare a result: An array of {tableName: "name", contents: [objects...]}
var result = [];
// Recursively export each table:
return exportNextTable ();
function exportNextTable () {
var table = tables.shift();
return table.toArray().then(function(a) {
result.push({
tableName: table.name,
contents: a
});
return tables.length > 0 ?
exportNextTable() :
result;
});
}
});
});
// Usage:
exportDatabase(db).then(function (dbObj) {
var json = JSON.stringify(dbObj);
alert (json);
}); |
@nponiros, @dfahlander it's probably better to close this issue in favour of #391 since the latter has more comments / participants. |
Addon for this: https://www.npmjs.com/package/dexie-export-import |
I would like to serialize the database and save it every day once as a text file, so later if it's needed I could unserialize and restore the database.
Does dexie.js has a built in function, to convert the database to string, and restore from a given string?
The text was updated successfully, but these errors were encountered: