Querying Entities with FlowEngine (Query Static and Query Dynamic Nodes)

Querying Entities with FlowEngine (Query Static and Query Dynamic Nodes)

This guide describes the Query Static and Query Dynamic nodes, showing examples for each. The methodology that follows the guide is the creation of an ontology, definitions of the queries and creation of the flow in FlowEngine.

Creation of the Entity (Ontology)

Start by creating an ontology called queryNoderedTest. Using the Creation Step by Step option, add the field "field", type string; and the field "value" of number type. Update the scheme and generate the instance.

 





queryNoderedTest ontology JSON
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "queryNoderedTest", "type": "object", "required": [ "queryNoderedTest" ], "properties": { "queryNoderedTest": { "type": "string", "$ref": "#/datos" } }, "datos": { "description": "Info queryNoderedTest", "type": "object", "required": [ "field", "value" ], "properties": { "field": { "type": "string" }, "value": { "type": "number" } } }, "description": "Creation of an ontology for the ues of query nodes in the Flow Engine.", "additionalProperties": true }

You can insert data using the CRUD of the ontology itself or using the FlowEngine and its Insert node.

Query Static node definition

A static query is based on the information added at the time of creation. Once the initial data is established, the fields cannot be modified.

Through this node, you can make several types of requests, both for data and for information, such as: select, update and delete.

Node properties

  • Name: Optional field used to identify the node with a specific name.

  • Ontology: Name of the ontology on which you want to query, update or delete data.

  • Query type: There are two options depending on the type of database you work with.

    1. SQL

    2. Native. Used if you have a MongoDB database..

  • Query: Sentence of query, update or deletion of data, to be launched.

The output data will depend on the type of query that is registered in the node.

Query Dynamic node definition

In a dynamic query, the information can be updated at any time. As with the static query, the requests that can be made are query, updated and deleted.

Node properties

  • Name: Optional field used to identify the node with a specific name.

This node expects to receive information from a function. This code will be passed through the function node. The parameters to be entered are:

  • Ontology: Name of the ontology on which you want to query, update or delete data.

  • Query type: There are two options depending on the type of database you work with.

    1. SQL

    2. Native. Used if you have a MongoDB database..

  • Query: Sentence of query, update or deletion of data, to be launched.

The output data will depend on the type of query that is registered in the node.

Flow creation in FlowEngine

Flow with Query Static

Start with the creation of a flow with static query. The nodes to be used are:

  • Inject. Activates the flow manually or at intervals.

  • Query Static. Used to perform the query with static databases.

  • Debug. Monitors the messages.



Query flow, select.

Double click on the query static node to open the window corresponding to the right image. These fields are filled in:

  • Name: select query

  • Ontologies available: queryNoderedTest

  • Ontology: queryNoderedTest

  • Query type: SQL

  • Query: select * from queryNoderedTest

In the Debug node, the msg. option is changed by complete msg object. The result that is obtained in the payload is a text message with the ontology's information. If you want to convert it to an object, you must make a parse object.

Update Flow, update.

Double click on the query static node to open the window corresponding to the right image. These fields are filled in:

  • Name: update query

  • Ontologies available: queryNoderedTest

  • Ontology: queryNoderedTest

  • Query type: SQL

  • Query: update queryNoderedTest set queryNoderedTest.value=24;

In the Debug node, the msg. option is changed by complete msg object. The result that is obtained in the payload is a counter with the amount of objects that have been modified. In this example, only one value is modified.

Delete flow, delete.

Double click on the query static node to open the window corresponding to the right image. These fields are filled in:

  • Name: delete query

  • Ontologies available: queryNoderedTest

  • Ontology: queryNoderedTest

  • Query type: SQL

  • Query: delete from queryNoderedTest where queryNoderedTest.value=24;

In the Debug node, the msg. option is changed by complete msg object. The result that is obtained in the payload is a counter with the amount of objects that have been deleted. In this example, only one value is deleted.

Flow with Query Dynamic

Start with the creation of a flow with dynamic query. The nodes to be used are:

  • Inject. Activates the flow manually or at intervals.

  • Function. JavaScript function against messages received by the node.

  • Query Static. Used to perform the query with static databases.

  • Debug. Monitors the messages.

 

In the window of the query dynamic node, the name that the node will take is entered, in this case, Dynamic query. The Debug option is also changed from msg to complete msg object.

In the Function node, the fields requested by the dynamic query are written, that is to say: ontology, query type and query; you can assign this node a name, query node.

msg.ontology = 'queryNoderedTest';

msg.queryType = 'SQL';

msg.query = 'Select * from queryNoderedTest where queryNoderedTest.value='+msg.payload.value;

return msg;

In this case, the query has been done with select but, as in the static case, you can write a query with update or delete.

The Inject node needs to be configured. In payload, choose the JSON option and enter the data you want to search. In the Function node, write msg.payload.filtro, so that, when writing the field in Inject, it will be done with filtro. The result would be: Payload: {"filtro": 28.6}.

Inject Node

Function Node



Click on Deploy and the flow is executed. The result you get as payload is an empty set since the search value, 28.6, is not included in the data.