Merge pull request #23 from h-sphere/fix/cte-names-registering-signals

fix: fixing issue with CTE names registering signals
This commit is contained in:
Kacper Kula 2024-12-20 13:52:32 +00:00 committed by GitHub
commit 6b14843516
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 23 additions and 6 deletions

View file

@ -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.

View file

@ -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",

View file

@ -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": {

View file

@ -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())

View file

@ -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 []
}

View file

@ -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"
}