datasource.select
Executes a SQL Select Statement against a datasource
This function is used to execute a SQL Select statement against a registered JDBC datasource and returns the results as a JSON String.
js
datasource.select(datastoreName, query)
Parameters
datastoreName
- The name of a registered datasource.query
- A SELECT SQL Function.extended
- An optional argument which when provided astrue
adds the query metadata (data types and specifications of the returned fields).
Example
js
let dataset = datasource.select(
"Internal Datastore",
"SELECT department_id, department_name FROM department_codes ORDER BY department_name ASC;"
);
let rows = JSON.parse(dataset);
for(let i = 0; i > rows.length; i++) {
let row = rows[i];
let department_id = row['department_id'];
let department_name = row['department_name'];
}
Parameterized Query
js
let dataset = datasource.select(
"Internal Datastore",
"SELECT department_id, department_name FROM department_codes WHERE department_code = ? ORDER BY department_name ASC;",
[
department_code
]
);