DataQuery Module
The DataQuery Module (apps/backend/modules/dataQuery) allows users to write and execute queries (SQL, HTTP) against registered Datasources.
Architecture
The core of execution is the QueryEngine.
Variable Interpolation
Queries support dynamic arguments using {{variable}} syntax.
- Frontend sends
argValues(e.g.,{ "limit": 10 }). - Parser scans the query string for mapped arguments.
- Engine performs parameter substitution (using proper prepared statements for SQL to prevent Injection).
AI Generation
The module includes an AI integration (generateAIPromptBasedQuery) that:
- Retrieves database schema.
- Sends schema + user prompt to LLM (Gemini).
- Returns a generated SQL query.
Query Engine (queryEngine/engine.js)
A framework-agnostic runner that:
- Accepts a
queryIDandexecutionParams. - Loads the correct driver based on
datasourceType. - Standardizes the output format.
Supported Drivers
- PostgreSQL: Uses
pgpool. - REST API: Uses
axios(implied). - RunJS: Executes sandboxed JavaScript.
Service API
runDataQueryByID
Executes a saved query.
await dataQueryService.runDataQueryByID({
userID: 1,
tenantID: 1,
dataQueryID: 100,
argValues: { "id": 5 }
});
runDataQueryByData
Executes an ad-hoc ("dirty") query. Used during the editing/testing phase before saving.
Warning: This creates a temporary queryID internally to satisfy the engine interface.