Shared query template processing for MemberJunction data providers. Handles parameter validation, type conversion, and Nunjucks template rendering for parameterized queries.
MemberJunction's RunQuery system supports parameterized SQL queries using Nunjucks templates (e.g., {{ status | sqlString }}). This package provides the QueryParameterProcessor class that both the SQL Server and PostgreSQL data providers use to:
The processor reads the current platform from RunQuerySQLFilterManager.Instance.Platform and adjusts behavior accordingly:
| Feature | SQL Server | PostgreSQL |
|---|---|---|
| Boolean values | 1 / 0 (BIT) |
true / false |
sqlBoolean filter |
Returns 1 or 0 |
Returns TRUE or FALSE |
sqlIdentifier filter |
[name] |
"name" |
sqlLikeContains / sqlLikeBegins / sqlLikeEnds filters |
Escapes % and _ with [%] [_] |
Escapes with \% \_ |
The Nunjucks environment is automatically recreated when the platform changes, since filters are baked in at creation time.
import { QueryParameterProcessor } from '@memberjunction/query-processor';
// Validate parameters against definitions
const validation = QueryParameterProcessor.validateParameters(
{ status: 'Active', limit: '10' },
query.Parameters
);
if (validation.success) {
// Process a query template
const result = QueryParameterProcessor.processQueryTemplate(
queryInfo,
userParams,
platformSpecificSQL // optional override
);
if (result.success) {
// result.processedSQL contains the rendered SQL
await executeSQL(result.processedSQL);
}
}
@memberjunction/core - For RunQuerySQLFilterManager, QueryInfo, QueryParameterInfo types@memberjunction/global - For MJGlobal utilitiesnunjucks - Template rendering engine