Skip to main content

Convert an OData Request to a SQL Query

Problem#

You want to intercept OData requests and convert them into SQL statements that make sense in OData context.

Solution#

Drag and drop an Http in node to receive the http requests. Use a Function node to define your database schema and connect it to Http in node. Drag and drop an Odata-in node and connect it to the Function node. Use a Debug node and connect it to the Odata-in node to log out the sql-statements in the debug window to verify.

Example#

img

Flow JSON
[{"id":"a62b22db.8b0d6","type":"http in","z":"29efa5eb.87dd3a","name":"","url":"/root/*","method":"get","upload":false,"swaggerDoc":"","x":140,"y":140,"wires":[["cf5f06eb.87b3c8"]]},{"id":"cf5f06eb.87b3c8","type":"function","z":"29efa5eb.87dd3a","name":"users EDM","func":"msg.model = {\n    namespace: \"ignite\",\n    entityTypes: {\n        \"users\": {\n            \"id\": {\"type\": \"Edm.Int32\", \"key\": true},\n            \"name\": {\"type\": \"Edm.String\"},            \n            \"username\": {\"type\": \"Edm.String\"}            \n        }\n    },   \n    entitySets: {\n        \"users\": {\n            entityType: \"ignite.users\"\n        }\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":140,"wires":[["9abf5f23.f36f5"]]},{"id":"75495530.2f6adc","type":"debug","z":"29efa5eb.87dd3a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":140,"wires":[]},{"id":"9abf5f23.f36f5","type":"odata in","z":"29efa5eb.87dd3a","name":"","x":520,"y":140,"wires":[["75495530.2f6adc"]]}]

Discussion#

This flow intercepts OData requests and converts them into database specific SQL statements.

These statements can be executed with the help of any desirable database node, we recommend using Ignite-Sequelize.