简体   繁体   中英

Odata $filter always returns empty array with node js and postgresql

I want to create a simple REST endpoint with OData and the $filter parameter. This is my filter query param: $filter=shoecolor eq 'black'

And this is my node js code:

import { createFilter } from "odata-v4-pg";
...
   var filter = createFilter(req.query.$filter + "");            
   const projectName = req.params.projectname;
   const storeName = req.params.storename; 
 
   this.logger.info(filter.where);      // prints: "shoecolor" = $1         

   var result = await this.database.any(`SELECT * FROM $1:name.$2:name WHERE ${filter.where}`, [projectName, storeName]);
   this.logger.info(result);           // prints an empty array!!!
...

Why is my SELECT with OData $filter always empty?

I found the solution on my own: I forgot to pass filter.parameters to the query. This link gives a good example: https://www.npmjs.com/package/odata-v4-pg?activeTab=readme

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM