跳到主要内容

INSERT

execute(sql, values)

execute(sql: string, values: any[])

try {
const sql = 'INSERT INTO `users`(`name`, `age`) VALUES (?, ?), (?,?)';
const values = ['Josh', 19, 'Page', 45];

const [result, fields] = await connection.execute(sql, values);

console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
  • 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
信息

The connection used for the query (execute) can be obtained through the createConnection, createPool or createPoolCluster methods.


execute(options)

execute(options: QueryOptions)

try {
const sql = 'INSERT INTO `users`(`name`, `age`) VALUES (?, ?), (?,?)';
const values = ['Josh', 19, 'Page', 45];

const [result, fields] = await connection.execute({
sql,
values,
// ... other options
});

console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
  • 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
信息

The connection used for the query (execute) can be obtained through the createConnection, createPool or createPoolCluster methods.


execute(options, values)

execute(options: QueryOptions, values: any[])

try {
const sql = 'INSERT INTO `users`(`name`, `age`) VALUES (?, ?), (?,?)';
const values = ['Josh', 19, 'Page', 45];

const [result, fields] = await connection.execute(
{
sql,
// ... other options
},
values
);

console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
  • 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
信息

The connection used for the query (execute) can be obtained through the createConnection, createPool or createPoolCluster methods.


Glossary

ResultSetHeader

ResultSetHeader Specification

QueryOptions

QueryOptions Specification