This section contains the following examples:
While the first two examples wait until the full result set is available, the third one returns immediately with the first batch of rows (usually 1000) and continuous to call the callback whenever the next batch is ready, until everything is transferred. This avoids blocking the execution environment in case of a long running query.
Press CTRL+C to copyconst result = await runSql( "SELECT Name as name," + "District as district, Population as pop FROM world.city WHERE Name = 'Kabul' " ); print(result);
Press CTRL+C to copyrunSqlWithCallback( "SELECT Name as name," + "District as district, Population as pop FROM world.city WHERE Name = 'Kabul' ", (ResultSetRows) => { print(ResultSetRows); } );
The output is:
[ { "name": "Kabul", "district": "Kabol", "pop": 1780000 } ]
Press CTRL+C to copyconst graphData = []; runSqlIterative( "SELECT rating as label , count(rating) as value FROM sakila.film " + "GROUP BY rating", (res: IResultSetData) => { if (res.rows) { res.rows.forEach((row, index) => { graphData.push({ label: row[1] as string, value: 25, }); }); } if (res.requestState.type === "OK") { print(res); } } );
The output is:
{ "requestState": { "type": "OK", "msg": "Full result set consisting of 5 rows transferred." }, "requestId": "6ee28aa2-2727-42d9-2bd9-d60f8d4abb64", "rows": [ [ "PG", 194 ], [ "G", 178 ], [ "NC-17", 210 ], [ "PG-13", 223 ], [ "R", 195 ] ], "columns": [ { "name": "label", "type": "ENUM", "length": 20 }, { "name": "value", "type": "INTEGER", "length": 21 } ], "done": true, "totalRowCount": 5, "executionTime": 0.0009739398956298828 }