MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / executePluginQuery

Function executePluginQuery

apps/desktop/main/worker/query/sql.ts:36–52  ·  view source on GitHub ↗
(
  sessionId: string,
  sql: string,
  params: unknown[] | Record<string, unknown> = []
)

Source from the content-addressed store, hash-verified

34 * Uses stmt.readonly via the adapter for safety.
35 */
36export function executePluginQuery<T = Record<string, unknown>>(
37 sessionId: string,
38 sql: string,
39 params: unknown[] | Record<string, unknown> = []
40): T[] {
41 const adapter = ensureAdapter(sessionId)
42 const stmt = adapter.prepare(sql.trim())
43
44 if (stmt.readonly === false) {
45 throw new Error('Plugin Security Violation: Only READ-ONLY statements are allowed.')
46 }
47
48 if (Array.isArray(params)) {
49 return stmt.all(...params) as T[]
50 }
51 return stmt.all(params) as T[]
52}
53
54/**
55 * Execute user SQL (SQL Lab).

Callers 1

dbWorker.tsFile · 0.90

Calls 3

ensureAdapterFunction · 0.85
prepareMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected