Documentation Home
MySQL Shell for VS Code


MySQL Shell for VS Code  /  TypeScript  /  DB Notebook: Retrieve Data with SELECT Statements

Pre-General Availability: 2024-05-02

9.2 DB Notebook: Retrieve Data with SELECT Statements

DB Notebook: Basic query returning one row

runSql(
"SELECT Name as label, District as district, Population as value FROM world.city WHERE Name = 'Kabul' ",
  (res: ResultSetRows) => {
    print(res);
  }
);

The output is:

[
    {
          "label": "Kabul",
          "district": "Kabol",
          "value": 1780000
    }
]

DB Notebook: Basic query returning multiple rows

const 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
}