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

Fix electron export issue #1242

Merged
merged 7 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/loot-core/src/platform/server/sqlite/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export async function openDatabase(pathOrBuffer?: string | Buffer): Database;

export function closeDatabase(db): void;

export function exportDatabase(db): void;
export async function exportDatabase(db): Buffer;
16 changes: 14 additions & 2 deletions packages/loot-core/src/platform/server/sqlite/index.electron.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Database from 'better-sqlite3';
import { v4 as uuidv4 } from 'uuid';

import { removeFile, readFile } from '../fs';

function verifyParamTypes(sql, arr) {
arr.forEach(val => {
Expand Down Expand Up @@ -100,6 +103,15 @@ export function closeDatabase(db) {
return db.close();
}

export function exportDatabase(db) {
return db.serialize();
export async function exportDatabase(db) {
// electron does not support better-sqlite serialize since v21
// save to file and read in the raw data.
let name = `backup-for-export-${uuidv4()}.db`;

await db.backup(name);

let data = await readFile(name);
await removeFile(name);

return data;
}
2 changes: 1 addition & 1 deletion packages/loot-core/src/platform/server/sqlite/index.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,6 @@ export function closeDatabase(db) {
db.close();
}

export function exportDatabase(db) {
export async function exportDatabase(db) {
return db.export();
}
3 changes: 2 additions & 1 deletion packages/loot-core/src/server/cloud-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export async function exportBuffer() {
`,
);

let dbContent = sqlite.exportDatabase(memDb);
let dbContent = await sqlite.exportDatabase(memDb);

sqlite.closeDatabase(memDb);

// mark it as a file that needs a new clock so when a new client
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1242.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [Shazib]
---

Fixed exporting data from Desktop (Electon) app.