Skip to content

Latest commit

 

History

History
217 lines (168 loc) · 4.56 KB

File metadata and controls

217 lines (168 loc) · 4.56 KB
sidebar_position tags
0
Prepared Statements
Placeholders
Parameters
execute

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import { FAQ } from '@site/src/components/FAQ'; import { ExternalCodeEmbed } from '@site/src/components/ExternalCodeEmbed';

INSERT

execute(sql, values)

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

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

  // highlight-next-line
  const [result, fields] = await connection.execute(sql, values);

  console.log(result);
  console.log(fields);
} catch (err) {
  console.log(err);
}
const sql = 'INSERT INTO `users`(`name`, `age`) VALUES (?, ?), (?,?)';
const values = ['Josh', 19, 'Page', 45];

connection.execute(sql, values, (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

:::info 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];

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

  console.log(result);
  console.log(fields);
} catch (err) {
  console.log(err);
}
const sql = 'INSERT INTO `users`(`name`, `age`) VALUES (?, ?), (?,?)';
const values = ['Josh', 19, 'Page', 45];

connection.execute(
  {
    sql,
    values,
    // ... 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

:::info 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];

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

  console.log(result);
  console.log(fields);
} catch (err) {
  console.log(err);
}
const sql = 'INSERT INTO `users`(`name`, `age`) VALUES (?, ?), (?,?)';
const values = ['Josh', 19, 'Page', 45];

connection.execute(
  {
    sql,
    // ... other options
  },
  values,
  (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

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


Glossary

ResultSetHeader

QueryOptions