Database Query

Simplified query functionality, accepts SQL script and query parameters and returns the result-set as a JSON object.

Version 3.x

Basic Usage

1
2
3
4
5
6
7
8
9
10
var query = require('db/v3/query');
var response = require('http/v3/response');

var sql = "SELECT * FROM MY_TABLE WHERE MY_COLUMN = ?";
var resultset = query.execute(sql, [1]);

response.println(JSON.stringify(resultset));

response.flush();
response.close();

Definition

Functions


Function Description Returns
execute(sql, parameters?, databaseType?, datasourceName?) Executes a SQL query against the selected databaseType and datasourceName with the provided parameters result-set as JSON object

parameters array supports primitives e.g. [1, โ€˜Johnโ€™, 34.56] or objects in format {โ€˜typeโ€™:โ€™[DATA_TYPE]โ€™, โ€˜valueโ€™:[VALUE]} e.g. [1, {โ€˜typeโ€™:โ€™CHARโ€™, โ€˜valueโ€™:โ€™ISBN19202323322โ€™}]

Compatibility

Rhino Nashorn V8
โœ… โœ… โœ…


Edit