Skip to content

Commit

Permalink
feat: only reset databases if there is more than 1 operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mokto committed May 11, 2024
1 parent 1a1c6f3 commit 84fb831
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, "''")}')`
);
Expand All @@ -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();
Expand Down

0 comments on commit 84fb831

Please sign in to comment.