From 5d9cd14a7b70dfd49c908fee8369c78c63270d1b Mon Sep 17 00:00:00 2001 From: stfrigerio Date: Sat, 22 Feb 2025 16:25:13 +0100 Subject: [PATCH] implemented requested changes --- main.ts | 6 ++---- src/commands/convertEntriesInNotes.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/main.ts b/main.ts index bd545ee..16bd481 100644 --- a/main.ts +++ b/main.ts @@ -40,7 +40,7 @@ export default class SqliteDBPlugin extends Plugin { this.addCommand({ id: "dump-table-to-notes", - name: "Dump Table to Notes", + name: "Dump table to notes", callback: async () => { await this.openDatabase(); // ensure DB is loaded @@ -107,10 +107,8 @@ class SqliteDBSettingTab extends PluginSettingTab { const { containerEl } = this; containerEl.empty(); - containerEl.createEl("h2", { text: "SQLite DB Plugin Settings" }); - new Setting(containerEl) - .setName("Database File Path") + .setName("Database file path") .setDesc("Absolute path to the .db file on disk.") .addText((text) => text diff --git a/src/commands/convertEntriesInNotes.ts b/src/commands/convertEntriesInNotes.ts index 29a8012..b62bcc6 100644 --- a/src/commands/convertEntriesInNotes.ts +++ b/src/commands/convertEntriesInNotes.ts @@ -62,12 +62,13 @@ export async function convertEntriesInNotes(dbService: DBService, tableName: str // Check if folder already exists; if not, create it let folder = app.vault.getAbstractFileByPath(targetFolderPath); - if (!folder) { - folder = await app.vault.createFolder(targetFolderPath); - } else if (!(folder instanceof TFolder)) { + if (folder && !(folder instanceof TFolder)) { new Notice(`A file named "${folderName}" already exists and is not a folder.`); return; } + if (!folder) { + folder = await app.vault.createFolder(targetFolderPath); + } // 4) Query *all* rows from the table const allRowsResult = db.exec(`SELECT * FROM "${tableName}";`); @@ -98,9 +99,11 @@ export async function convertEntriesInNotes(dbService: DBService, tableName: str // If file already exists, append a suffix let suffix = 1; - while (app.vault.getAbstractFileByPath(notePath)) { + let existingFile = app.vault.getAbstractFileByPath(notePath); + while (existingFile && existingFile instanceof TFile) { suffix++; notePath = `${targetFolderPath}/${safeFileName}_${suffix}.md`; + existingFile = app.vault.getAbstractFileByPath(notePath); } // Build frontmatter with all columns