QueryIterator
Constructors
Constructor
new QueryIterator():
QueryIterator
Returns
QueryIterator
Methods
toArray()
statictoArray<TRow>(result):TRow[]
Maps the rows from a DBResultSet by using a default mapping.
Every cell is returned as string!
context.enableModules();
const { QueryIterator } = require("ou.sp.QueryIterator");
const dbUser = util.getEnvironment("OUSP_DATABASE_USER");
const dbPassword = util.getEnvironment("OUSP_DATABASE_PASSWORD");
const db = new DBConnection("odbc", "ousp", dbUser, dbPassword);
const result = db.executeQuery("SELECT id, costcenter FROM costcenter");
const rows = QueryIterator.toArray(result);
// [{ id: "1", costcenter: "K10000"}, { id: "2", costcenter: "K10001"}]
Type Parameters
TRow
TRow
Parameters
result
DBResultSet
The DBResultSet instance
Returns
TRow[]
An array of rows
map()
Call Signature
staticmap<TRow>(result):TRow[]
Maps the rows from a DBResultSet by using a default mapping.
Every cell is returned as string!
context.enableModules();
const { QueryIterator } = require("ou.sp.QueryIterator");
const dbUser = util.getEnvironment("OUSP_DATABASE_USER");
const dbPassword = util.getEnvironment("OUSP_DATABASE_PASSWORD");
const db = new DBConnection("odbc", "ousp", dbUser, dbPassword);
const result = db.executeQuery("SELECT id, costcenter FROM costcenter");
const rows = QueryIterator.map(result);
// [{ id: "1", costcenter: "K10000"}, { id: "2", costcenter: "K10001"}]
Type Parameters
TRow
TRow
Parameters
result
DBResultSet
The DBResultSet instance
Returns
TRow[]
An array of rows
Call Signature
staticmap<TRow>(result,mapping,replace?):TRow[]
Maps the rows from a DBResultSet by a given mapping.
It's recommend to specify the columns in the select query.
context.enableModules();
const { QueryIterator } = require("ou.sp.QueryIterator");
const dbUser = util.getEnvironment("OUSP_DATABASE_USER");
const dbPassword = util.getEnvironment("OUSP_DATABASE_PASSWORD");
const db = new DBConnection("odbc", "ousp", dbUser, dbPassword);
const result = db.executeQuery("SELECT id, costcenter FROM costcenter");
const rows = QueryIterator.map(result, [
{
name: "id",
action: "getInt",
},
{
name: "name",
action: "getString",
},
],
{ replaceEveryAction: { search: null, replace: "" } });
Other example using the index option in mapping
context.enableModules();
const { QueryIterator } = require("ou.sp.QueryIterator");
const dbUser = util.getEnvironment("OUSP_DATABASE_USER");
const dbPassword = util.getEnvironment("OUSP_DATABASE_PASSWORD");
const db = new DBConnection("odbc", "ousp", dbUser, dbPassword);
const result = db.executeQuery("SELECT id, costcenter FROM costcenter");
const rows = QueryIterator.map(result, [
{
name: "name",
index: 1,
action: "getString",
},
{
name: "id",
index: 0,
action: "getInt",
},
]);
Type Parameters
TRow
TRow
Parameters
result
DBResultSet
The DBResultSet instance
mapping
An array of column mapping information
replace?
Optional replace options
Returns
TRow[]
An array of rows
Call Signature
staticmap<TRow>(result,callback,replace?):TRow[]
Maps the rows from a DBResultSet by a callback
context.enableModules();
const { QueryIterator } = require("ou.sp.QueryIterator");
const dbUser = util.getEnvironment("OUSP_DATABASE_USER");
const dbPassword = util.getEnvironment("OUSP_DATABASE_PASSWORD");
const db = new DBConnection("odbc", "ousp", dbUser, dbPassword);
const result = db.executeQuery("SELECT id, costcenter FROM costcenter");
const rows = QueryIterator.map(result, (options) => {
return {
rowNo: options.rowIndex + 1,
id: options.result.getInt(options.columns.id),
name: options.result.getString(options.columns.costcenter),
}
});
Type Parameters
TRow
TRow
Parameters
result
DBResultSet
The DBResultSet instance
callback
QueryIteratorCallback<TRow>
A iteration callback, triggered on every row.
replace?
Optional replace options
Returns
TRow[]
An array of rows