Registry / database / ts-rsql-query

ts-rsql-query

JSON →
library1.3.4jsnpmunverified

ts-rsql-query v1.3.4 transforms the AST from ts-rsql into a SQL WHERE clause with parameterized values. It provides an SqlContext with configurable selectors, operators, keyword casing, and parameter offset support. Unlike generic SQL builders, it is purpose-built for RSQL query strings and integrates tightly with ts-rsql's parser. Released under MIT, it follows a stable release cadence with active maintenance. Key differentiators include plugin support for custom operators and alignment with the ts-rsql ecosystem.

npm install ts-rsql-query
INSTALL
IMPORT
SIG · TS-RSQL-QUERY
T
ts-rsql-query
databasejavascriptv1.3.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SqlContext
import { SqlContext } from 'ts-rsql-query'
const SqlContext = require('ts-rsql-query');
ESM-only; CommonJS require will fail. Use named import.
queryFromRsql
import { queryFromRsql } from 'ts-rsql-query'
import queryFromRsql from 'ts-rsql-query';
Default import not available; must use named import.
queryFromRsql
import { queryFromRsql } from 'ts-rsql-query'
import { queryFromRsql } from 'ts-rsql'
queryFromRsql resides in ts-rsql-query, not ts-rsql. ts-rsql only exports RsqlParser.

Demonstrates initializing an SqlContext with selectors and calling queryFromRsql to generate a parameterized SQL WHERE clause.

import { queryFromRsql, SqlContext } from 'ts-rsql-query'; // Setup context const context: SqlContext = { values: [], selectors: { points: { column: 'pointbalance', type: 'NUMBER', relation: 'users', }, name: { column: 'lastname', type: 'VARCHAR', }, }, whereKeywordPrefix: ' ', }; const filter = 'points>500;name=le*'; const result = queryFromRsql(context, filter); console.log('SQL:', result.sql); // SQL: WHERE pointbalance>$1 AND lastname LIKE $2 console.log('Values:', result.values); // Values: [500, 'le%']
Debug
Known issues
gotchaSelector resolution fails silently if a selector is not defined in the context when lax is false
fix
Ensure all selectors referenced in the RSQL string are defined in SqlContext selectors, or set lax: true to skip undefined selectors.
affects: <1.4.0
breakingThe 'values' array must include any existing query parameters before generating predicates. Failure to do so results in incorrect parameter numbering.
fix
Pre-populate the 'values' array with any parameters from the base query before passing to queryFromRsql.
affects: >=0.1.0
deprecatedThe 'whereKeywordPrefix' option has been deprecated in favor of a static ' ' prefix. Custom prefixes may break in future versions.
fix
Avoid using whereKeywordPrefix; rely on the default or format manually.
affects: >=1.3.0
gotchaOrder-by columns in the RSQL string are passed through without escaping; they are not matched against selectors.
fix
Whitelist or sanitize order-by values externally to prevent SQL injection.
affects: >=0.1.0
breakingTypeScript types for selector config changed: 'type' field type changed from enum to string union.
fix
Use string literals like 'NUMBER' | 'VARCHAR' instead of importing an enum.
affects: >=1.2.0
Errors
Common errors & fixes
TypeError: context.selectors[selector] is undefined
RSQL string references a selector not defined in SqlContext.selectors and lax is not set to true.
fix
Define the missing selector in the selectors map or set lax: true in SqlContext.
Cannot find module 'ts-rsql-query' or its corresponding type declarations.
The package is ESM-only; TypeScript may need 'moduleResolution': 'node16' or 'bundler'.
fix
Set 'moduleResolution' to 'node16' or 'bundler' in tsconfig.json and ensure 'module' is 'ESNext' or similar.
Property 'type' does not exist on type '{ column: string; relation?: string; }'
Earlier versions of selector config did not require a 'type' field; v1.2.0+ enforces it.
fix
Add a 'type' field to each selector config (e.g., type: 'NUMBER' | 'VARCHAR').
Cannot read properties of undefined (reading 'column')
The RSQL parser (ts-rsql) may produce unexpected AST nodes (e.g., order-by with no selector) that ts-rsql-query fails to handle gracefully.
fix
Validate the RSQL string to ensure order-by parts refer to valid selectors, or upgrade ts-rsql-query to a version with better error handling.
Upgrade
Version history
1.3.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
16
Meta
2
OpenAI (training)
1
Resources
ts-rsql-query — npm install ts-rsql-query · libregistry