Registry / database / odata-to-sql

odata-to-sql

JSON →
library0.10.2jsnpmunverified

Node.js library that translates OData query strings into SQL statements. Version 0.10.2 is the latest stable release, maintained on a low cadence. It supports basic OData operators ($filter, $orderby, $top, $skip) and translates them to parameterized SQL. Unlike full ORM solutions, this is a focused, zero-dependency query translator, producing raw SQL strings for use with any database driver. It does not handle OData $expand or complex joins.

npm install odata-to-sql
INSTALL
IMPORT
SIG · ODATA-TO-SQL
O
odata-to-sql
databasejavascriptv0.10.2
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.

default
import oDataToSql from 'odata-to-sql'
const oDataToSql = require('odata-to-sql')
The package exports a default function. Use default import for ESM. There is no named export.

Parse OData query string and generate parameterized SQL with field mapping.

import oDataToSql from 'odata-to-sql'; const oDataQuery = "$filter=id eq 42&$orderby=name desc&$top=10&$skip=5"; const result = oDataToSql(oDataQuery, { table: 'users', fields: { id: { dbName: 'user_id', alias: 'userId' }, name: { dbName: 'user_name' }, email: { dbName: 'email' } } }); console.log(result); // Output: { // sql: "SELECT * FROM (SELECT user_id AS userId, user_name, email FROM users) AS __tbl WHERE user_id = $1 ORDER BY user_name DESC LIMIT 10 OFFSET 5", // params: [42] // }
Debug
Known issues
gotchaOData $expand is not supported; complex navigation properties will be ignored.
fix
Manually join additional tables or handle expansions separately.
affects: >=0.0.0
gotchaAll columns are selected as * in subquery; field mapping only applies to WHERE, ORDER BY, etc., not to SELECT clause.
fix
The library does not restrict selected columns; use post-processing or accept that all table columns are returned.
affects: >=0.0.0
gotchaOnly standard OData operators are supported; custom functions or lambda operators may cause errors.
fix
Ensure OData query uses only $filter, $orderby, $top, $skip, $inlinecount (limited support).
affects: >=0.0.0
Errors
Common errors & fixes
Cannot read properties of undefined (reading 'split')
Passing an undefined or malformed OData query string.
fix
Ensure the OData query string is a string, even if empty: `''`.
Field 'xyz' not found in fields definition
Referencing a field in OData query that is not mapped in the fields object.
fix
Add the missing field to the fields object with proper dbName mapping.
Upgrade
Version history
0.10.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
odata-to-sql — npm install odata-to-sql · libregistry