fix: make FTS5 optional for template search (fixes Claude Desktop compatibility)
- Added runtime FTS5 detection in database adapters - Removed FTS5 from required schema to prevent "no such module" errors - FTS5 tables/triggers created conditionally only if supported - Template search automatically falls back to LIKE when FTS5 unavailable - Works in ALL SQLite environments (Claude Desktop, restricted envs, etc.) This ensures search_templates() works correctly regardless of SQLite build, while still providing optimal performance when FTS5 is available. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ export interface DatabaseAdapter {
|
||||
pragma(key: string, value?: any): any;
|
||||
readonly inTransaction: boolean;
|
||||
transaction<T>(fn: () => T): T;
|
||||
checkFTS5Support(): boolean;
|
||||
}
|
||||
|
||||
export interface PreparedStatement {
|
||||
@@ -174,6 +175,17 @@ class BetterSQLiteAdapter implements DatabaseAdapter {
|
||||
transaction<T>(fn: () => T): T {
|
||||
return this.db.transaction(fn)();
|
||||
}
|
||||
|
||||
checkFTS5Support(): boolean {
|
||||
try {
|
||||
// Test if FTS5 is available
|
||||
this.exec("CREATE VIRTUAL TABLE IF NOT EXISTS test_fts5 USING fts5(content);");
|
||||
this.exec("DROP TABLE IF EXISTS test_fts5;");
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,6 +246,18 @@ class SQLJSAdapter implements DatabaseAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
checkFTS5Support(): boolean {
|
||||
try {
|
||||
// Test if FTS5 is available
|
||||
this.exec("CREATE VIRTUAL TABLE IF NOT EXISTS test_fts5 USING fts5(content);");
|
||||
this.exec("DROP TABLE IF EXISTS test_fts5;");
|
||||
return true;
|
||||
} catch (error) {
|
||||
// sql.js doesn't support FTS5
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private scheduleSave(): void {
|
||||
if (this.saveTimer) {
|
||||
clearTimeout(this.saveTimer);
|
||||
|
||||
@@ -47,7 +47,5 @@ CREATE INDEX IF NOT EXISTS idx_template_nodes ON templates(nodes_used);
|
||||
CREATE INDEX IF NOT EXISTS idx_template_updated ON templates(updated_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_template_name ON templates(name);
|
||||
|
||||
-- Full-text search for templates
|
||||
CREATE VIRTUAL TABLE IF NOT EXISTS templates_fts USING fts5(
|
||||
name, description, content=templates
|
||||
);
|
||||
-- Note: FTS5 tables are created conditionally at runtime if FTS5 is supported
|
||||
-- See template-repository.ts initializeFTS5() method
|
||||
Reference in New Issue
Block a user