Registry / database / odata-v4-typeorm

odata-v4-typeorm

JSON →
library0.1.2jsnpmunverified

OData V4 query parser and compiler for TypeORM (0.1.2). Converts OData v4 query strings (e.g., $filter, $select, $orderby, $top, $skip, $expand, $apply) into TypeORM QueryBuilder or repository queries. Supports Express and NestJS middleware. Lightweight alternative to full OData frameworks. Limited to SQL databases; no NoSQL support. Regularly released but early-stage (0.x). Ships TypeScript definitions.

npm install odata-v4-typeorm
INSTALL
IMPORT
SIG · ODATA-V4-TYPEORM
O
odata-v4-typeorm
databasejavascriptv0.1.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.

odataQuery
import { odataQuery } from 'odata-v4-typeorm';
const odataQuery = require('odata-v4-typeorm');
Both ESM and CJS supported. 'odataQuery' is a middleware function expecting a TypeORM Repository as argument.
executeQuery
import { executeQuery } from 'odata-v4-typeorm';
import executeQuery from 'odata-v4-typeorm';
Named export, not default. Use with repository or query builder and query string object.
ODataQuery
import { ODataQuery } from 'odata-v4-typeorm';
TypeScript type for the query options object. Optional import for type checking.

Express middleware that automatically parses OData v4 query parameters from the request URL and returns filtered/sorted/paginated data from a TypeORM repository.

import express from 'express'; import { odataQuery } from 'odata-v4-typeorm'; import { getRepository } from 'typeorm'; import { User } from './entities/user'; const app = express(); const usersRepository = getRepository(User); app.get('/api/users', odataQuery(usersRepository)); app.listen(3001, () => console.log('Example app listening on port 3001!'));
Debug
Known issues
gotchaThe library only translates OData query parameters; it does not build the full OData response envelope (no @odata.context, count, etc.).
fix
Manually wrap the response with OData metadata if needed, or use a dedicated OData framework (e.g., odata-v4-server).
affects: >=0.0.0
breakingBreaking change in v0.0.11: $apply (aggregation) not supported. Use $filter and custom aggregation.
fix
Upgrade to v0.1.0+ which includes basic $apply support for count, sum, min, max.
affects: <0.1.0
deprecatedexecuteQuery signature changed in v0.0.10: second parameter is now query object, not string.
fix
Update calls to executeQuery(repository, req.query) instead of executeQuery(repository, req.queryString).
affects: <0.0.10
gotchaTypeORM versions >=0.3.0 use DataSource, not Connection. This library relies on Connection for repository injection; may require adapter.
fix
Use TypeORM 0.2.x or wrap DataSource to provide Connection-compatible repository.
affects: >=0.0.0
gotcha$expand is not supported by default; you must manually define relations in your entity.
fix
Use TypeORM's QueryBuilder with leftJoinAndSelect and pass a pre-built queryBuilder to executeQuery.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: odataQuery is not a function
Incorrect import; using default import instead of named import.
fix
Use import { odataQuery } from 'odata-v4-typeorm';
Cannot read property 'createQueryBuilder' of undefined
executeQuery called with a Repository that is not initialized (null/undefined).
fix
Ensure the repository is properly obtained via getRepository() or dependency injection.
No metadata for "User" was found
Entity not registered in TypeORM connection options.
fix
Add the User entity to entities array in createConnection() or DataSource options.
getRepository is not a function
Using TypeORM 0.3+ where getRepository is no longer exported. Use dataSource.getRepository(User).
fix
Update to TypeORM 0.2.x or use dataSource.getRepository().
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
typeormrequiredCore dependency; provides repository and query builder APIs.
Agent activity
2 hits · last 30 days
node
2
Resources
odata-v4-typeorm — npm install odata-v4-typeorm · libregistry