From e28d02afe6a4ff68599ec36ace2a961ab6e74b61 Mon Sep 17 00:00:00 2001 From: Kacper Kula Date: Fri, 20 Dec 2024 13:52:02 +0000 Subject: [PATCH] fix: fixing issue with CTE names registering signals --- CHANGELOG.md | 3 +++ manifest.json | 2 +- package.json | 2 +- src/SqlSealCodeblockHandler.ts | 8 +++++--- src/sqlReparseTables.ts | 11 +++++++++++ versions.json | 3 ++- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 483d473..1c824c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.12.2 +fix: Fixed issue with CTE table names being incorrectly processed causing error + # 0.12.1 fix: Fixed issue with the library on mobile - now it should load properly. diff --git a/manifest.json b/manifest.json index 1842aa7..149ae56 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "sqlseal", "name": "SQLSeal", - "version": "0.12.1", + "version": "0.12.2", "minAppVersion": "0.15.0", "description": "Use SQL in your notes to query your vault files and CSV content.", "author": "hypersphere", diff --git a/package.json b/package.json index 9cccff6..3d62cf0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sqlseal", - "version": "0.12.1", + "version": "0.12.2", "description": "A plugin for Obsidian that allows you to run SQL queries on your notes.", "main": "main.js", "scripts": { diff --git a/src/SqlSealCodeblockHandler.ts b/src/SqlSealCodeblockHandler.ts index 43c2faa..6300713 100644 --- a/src/SqlSealCodeblockHandler.ts +++ b/src/SqlSealCodeblockHandler.ts @@ -2,7 +2,7 @@ import { App, MarkdownPostProcessorContext } from "obsidian" import { displayError, displayNotice } from "./ui" import { resolveFrontmatter } from "./frontmatter" import { hashString } from "./hash" -import { prefixedIfNotGlobal, updateTables } from "./sqlReparseTables" +import { extractCtes, prefixedIfNotGlobal, updateTables } from "./sqlReparseTables" import { SqlSealDatabase } from "./database" import { Logger } from "./logger" import { TablesManager } from "./dataLoader/collections/tablesManager" @@ -12,7 +12,7 @@ import { RendererRegistry, RenderReturn } from "./rendererRegistry" export class SqlSealCodeblockHandler { get globalTables() { - return ['files', 'tags', 'tasks'] // Make this come from SealFileSync and plugins. + return ['files', 'tags', 'tasks', 'xyz'] // Make this come from SealFileSync and plugins. } constructor( private readonly app: App, @@ -88,7 +88,9 @@ export class SqlSealCodeblockHandler { try { if (results.queryPart) { const { statement, tables } = updateTables(results.queryPart!, [...this.globalTables], prefix) - this.setupQuerySignals({ statement, tables }, renderer!, ctx, el) + const ctes = extractCtes(results.queryPart) + const tablesWithoutCtes = tables.filter(t => !ctes.includes(t)) + this.setupQuerySignals({ statement, tables: tablesWithoutCtes }, renderer!, ctx, el) } } catch (e) { renderer!.error(e.toString()) diff --git a/src/sqlReparseTables.ts b/src/sqlReparseTables.ts index 3d70a79..7e35dd9 100644 --- a/src/sqlReparseTables.ts +++ b/src/sqlReparseTables.ts @@ -77,4 +77,15 @@ export const updateTables = (selectStatement: string, globalTables: string[], pr } else { throw new Error('Invalid Statement. Only single SELECTs are accepted at the moment.') } +} + +export const extractCtes = (selectStatement: string) => { + const parser = new Parser() + const { ast } = parser.parse(selectStatement) + if (!Array.isArray(ast) && ast.type === 'select') { + if (ast.with) { + return ast.with.map(w => w.name.value) + } + } + return [] } \ No newline at end of file diff --git a/versions.json b/versions.json index f71823b..8b367d3 100644 --- a/versions.json +++ b/versions.json @@ -15,5 +15,6 @@ "0.10.1": "0.15.0", "0.11.0": "0.15.0", "0.12.0": "0.15.0", - "0.12.1": "0.15.0" + "0.12.1": "0.15.0", + "0.12.2": "0.15.0" } \ No newline at end of file