mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-28 01:58:40 -05:00
Fix electron export issue (#1242)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -199,6 +199,6 @@ export function closeDatabase(db) {
|
||||
db.close();
|
||||
}
|
||||
|
||||
export function exportDatabase(db) {
|
||||
export async function exportDatabase(db) {
|
||||
return db.export();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
6
upcoming-release-notes/1242.md
Normal file
6
upcoming-release-notes/1242.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [Shazib]
|
||||
---
|
||||
|
||||
Fixed exporting data from Desktop (Electon) app.
|
||||
Reference in New Issue
Block a user