Skip to content

API Docs - v5.0.2

Tested Siddhi Core version: 5.1.0

It could also support other Siddhi Core minor versions.

Js

eval (Function)

This extension evaluates a given string and return the output according to the user specified data type.

Syntax

<INT|LONG|DOUBLE|FLOAT|STRING|BOOL|OBJECT> js:eval(<STRING> expression, <STRING> return.type)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
expression Any single line js expression or function. STRING No Yes
return.type The return type of the evaluated expression. Supported types are int|long|float|double|bool|string. STRING No No

Examples EXAMPLE 1

js:eval("700 > 800", 'bool')

In this example, the expression 700 > 800 will be evaluated and return result as false because user specified return type as bool.

Script

javascript (Script)

This extension allows you to include JavaScript functions within the Siddhi Query Language.

Syntax

define function <FunctionName>[javascript] return <type> {
    // Script code
};

Examples EXAMPLE 1

define function concatJ[JavaScript] return string {"  var str1 = data[0];
 var str2 = data[1];
 var str3 = data[2];
 var res = str1.concat(str2,str3);
 return res;
};

This JS function will consume 3 var variables, concatenate them and will return as a string