Skip to main content

6. SQL executor

The SQL executor is a DataQL extension module. A fragment declares database statements and parameters, then runs as a function. Query results can be used in expressions and transformations.

Requirements

The application must load dataql-sqlproc and provide database connections. See DataQL engine: SQL executor for setup. This chapter covers script usage.

hint FRAGMENT_SQL_OPEN_PACKAGE = 'off';
hint FRAGMENT_SQL_COLUMN_CASE = 'lower';
var find = @@selectSql(minAge)<%
SELECT name, age FROM people WHERE age >= #{minAge} ORDER BY id
%>;
return find(25) => [{"name", "nextAge": age + 1}];

Using the people table in SQL execution, this returns [{"name":"Alice","nextAge":26},{"name":"Bob","nextAge":31}].

Guide​

For custom rules, dialects and handlers, see engine extensions.