From 84fb831397f85d3a8dc8b60e02b6b8857f29cc44 Mon Sep 17 00:00:00 2001 From: Theo Mathieu Date: Sat, 11 May 2024 13:17:30 +0200 Subject: [PATCH] feat: only reset databases if there is more than 1 operation --- src/lib/utils/db.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/db.ts b/src/lib/utils/db.ts index 1783bc4..566edbd 100644 --- a/src/lib/utils/db.ts +++ b/src/lib/utils/db.ts @@ -28,9 +28,13 @@ export const resetDatabase = () => { }; export const prepareDatabase = async (jsonFile: string | object) => { - const db = resetDatabase(); const jsonFileData = typeof jsonFile === 'string' ? JSON.parse(jsonFile) : jsonFile; const data = await parseOpenAPI(jsonFileData); + const countOperations = Object.keys(data.operations).length + Object.keys(data.webhooks).length; + if (countOperations === 0) { + return countOperations; + } + const db = resetDatabase(); db.exec( `INSERT INTO GlobalData (data) VALUES ('${JSON.stringify(data.global).replace(/'/g, "''")}')` ); @@ -46,6 +50,8 @@ export const prepareDatabase = async (jsonFile: string | object) => { `INSERT INTO Webhooks (webhook_id, data) VALUES ('${webhookId}', '${JSON.stringify(data.webhooks[webhookId]).replace(/'/g, "''")}')` ); }); + + return countOperations; }; export const getGlobalData = async () => { const db = getDb();