Fix electron export issue (#1242)

This commit is contained in:
Shazib Hussain
2023-07-02 13:32:55 +01:00
committed by GitHub
parent f5ea9d0fda
commit 7a5bf2ffc4
5 changed files with 24 additions and 5 deletions

View File

@@ -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;

View File

@@ -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 => {
@@ -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;
}

View File

@@ -199,6 +199,6 @@ export function closeDatabase(db) {
db.close();
}
export function exportDatabase(db) {
export async function exportDatabase(db) {
return db.export();
}

View File

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

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [Shazib]
---
Fixed exporting data from Desktop (Electon) app.