INSERT
The examples below also work for the execute method.
query(sql)
query(sql: string)
- promise.js
 - callback.js
 
try {
  const sql =
    'INSERT INTO `users`(`name`, `age`) VALUES ("Josh", 19), ("Page", 45)';
  const [result, fields] = await connection.query(sql);
  console.log(result);
  console.log(fields);
} catch (err) {
  console.log(err);
}
const sql =
  'INSERT INTO `users`(`name`, `age`) VALUES ("Josh", 19), ("Page", 45)';
connection.query(sql, (err, result, fields) => {
  if (err instanceof Error) {
    console.log(err);
    return;
  }
  console.log(result);
  console.log(fields);
});
- result: contains a ResultSetHeader object, which provides details about the operation executed by the server.
 - fields contains extra meta data about the operation, if available
 
informação
The connection used for the query (.query()) can be obtained through the createConnection, createPool or createPoolCluster methods.
query(options)
query(options: QueryOptions)
- promise.js
 - callback.js
 
try {
  const sql =
    'INSERT INTO `users`(`name`, `age`) VALUES ("Josh", 19), ("Page", 45)';
  const [result, fields] = await connection.query({
    sql,
    // ... other options
  });
  console.log(result);
  console.log(fields);
} catch (err) {
  console.log(err);
}
const sql =
  'INSERT INTO `users`(`name`, `age`) VALUES ("Josh", 19), ("Page", 45)';
connection.query(
  {
    sql,
    // ... other options
  },
  (err, result, fields) => {
    if (err instanceof Error) {
      console.log(err);
      return;
    }
    console.log(result);
    console.log(fields);
  }
);
- result: contains a ResultSetHeader object, which provides details about the operation executed by the server.
 - fields contains extra meta data about the operation, if available
 
informação
The connection used for the query (.query()) can be obtained through the createConnection, createPool or createPoolCluster methods.