Skip to content
Snippets Groups Projects
Unverified Commit 7a5bf2ff authored by Shazib Hussain's avatar Shazib Hussain Committed by GitHub
Browse files

Fix electron export issue (#1242)

parent f5ea9d0f
No related branches found
No related tags found
No related merge requests found
...@@ -29,4 +29,4 @@ export async function openDatabase(pathOrBuffer?: string | Buffer): Database; ...@@ -29,4 +29,4 @@ export async function openDatabase(pathOrBuffer?: string | Buffer): Database;
export function closeDatabase(db): void; export function closeDatabase(db): void;
export function exportDatabase(db): void; export async function exportDatabase(db): Buffer;
import Database from 'better-sqlite3'; import Database from 'better-sqlite3';
import { v4 as uuidv4 } from 'uuid';
import { removeFile, readFile } from '../fs';
function verifyParamTypes(sql, arr) { function verifyParamTypes(sql, arr) {
arr.forEach(val => { arr.forEach(val => {
...@@ -100,6 +103,15 @@ export function closeDatabase(db) { ...@@ -100,6 +103,15 @@ export function closeDatabase(db) {
return db.close(); return db.close();
} }
export function exportDatabase(db) { export async function exportDatabase(db) {
return db.serialize(); // 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;
} }
...@@ -199,6 +199,6 @@ export function closeDatabase(db) { ...@@ -199,6 +199,6 @@ export function closeDatabase(db) {
db.close(); db.close();
} }
export function exportDatabase(db) { export async function exportDatabase(db) {
return db.export(); return db.export();
} }
...@@ -148,7 +148,8 @@ export async function exportBuffer() { ...@@ -148,7 +148,8 @@ export async function exportBuffer() {
`, `,
); );
let dbContent = sqlite.exportDatabase(memDb); let dbContent = await sqlite.exportDatabase(memDb);
sqlite.closeDatabase(memDb); sqlite.closeDatabase(memDb);
// mark it as a file that needs a new clock so when a new client // mark it as a file that needs a new clock so when a new client
......
---
category: Bugfix
authors: [Shazib]
---
Fixed exporting data from Desktop (Electon) app.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment