Registry / database / odata-v4-pg

odata-v4-pg

JSON →
library0.1.1jsnpmunverified

OData V4 to PostgreSQL query compiler that converts OData query segments ($filter, $select, $orderby, $expand, $skip, $top) into SQL statements for PostgreSQL. Version 0.1.1 is the latest, with sporadic releases. It differs from alternatives like odata-v4-mysql by targeting PostgreSQL, supporting all standard OData query options, and providing a simple createFilter function that returns { where, parameters } for direct use with the pg driver.

npm install odata-v4-pg
INSTALL
IMPORT
SIG · ODATA-V4-PG
O
odata-v4-pg
databasejavascriptv0.1.1
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.

createFilter
import { createFilter } from 'odata-v4-pg'
const createFilter = require('odata-v4-pg').createFilter
Works in both ESM and CJS; TypeScript types included.
createQuery
import { createQuery } from 'odata-v4-pg'
const createQuery = require('odata-v4-pg').createQuery
Alias for createFilter with additional query building.
ODataServer
import { ODataServer } from 'odata-v4-pg'
const ODataServer = require('odata-v4-pg').ODataServer
Class for full OData server integration; requires additional setup.

Demonstrates parsing an OData $filter expression and executing the resulting SQL query against PostgreSQL.

import { createFilter } from 'odata-v4-pg'; import { Client } from 'pg'; const client = new Client({ connectionString: process.env.DATABASE_URL ?? '' }); await client.connect(); const filter = createFilter("Id eq 42"); const res = await client.query(`SELECT * FROM Users WHERE ${filter.where}`, filter.parameters); console.log(res.rows); await client.end();
Debug
Known issues
breakingcreateFilter() returns an object with `where` and `parameters` properties, not a SQL string directly.
fix
Use filter.where for SQL clause and filter.parameters for parameterized values.
affects: >=0.0.0
gotchaOData `$expand` support is limited to simple navigation properties; complex nested expands may not work.
fix
Avoid deep or multiple nested $expand queries; flatten relations manually.
affects: >=0.0.0
deprecatedThe `ODataServer` class from `odata-v4-server` is now deprecated in favor of standalone express middleware.
fix
Use `createFilter()` directly with your own Express endpoints.
affects: >=0.1.0
gotchaParameterized queries are required; do not concatenate filter.where into SQL strings to avoid injection.
fix
Always pass filter.parameters as query parameters to the pg client.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'where' of 'createFilter(...)' as it is undefined.
The OData filter string is invalid or empty.
fix
Ensure $filter is a valid OData expression string (e.g., 'Id eq 42').
error: column "Id" does not exist
Column names from $filter are case-sensitive and must match PostgreSQL schema exactly.
fix
Use exact column names (e.g., 'id' instead of 'Id') or quote them accordingly.
Module 'odata-v4-pg' has no exported member 'createFilter'
Importing from wrong path or using incorrect version.
fix
Install the latest version (npm install odata-v4-pg@latest) and use `import { createFilter } from 'odata-v4-pg'`.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
odata-v4-parserrequiredParses OData query strings into AST
odata-v4-sqlrequiredConverts AST into SQL statements
Agent activity
4 hits · last 30 days
node
4
Resources
odata-v4-pg — npm install odata-v4-pg · libregistry