interface

SQL.ResultMetadata

interface ResultMetadata

Properties of the array that a query resolves to, next to the rows. They are accessors on the prototype, not own properties, so console.log, Object.keys, JSON.stringify and spreading only see the rows.

A query with several statements (.simple(), a MySQL CALL) resolves to a plain array of results. The metadata is on each inner array.

  • affectedRows: number

    The number of rows that an INSERT, UPDATE, DELETE or MERGE wrote. 0 for a statement that writes nothing.

    PostgreSQL tags CREATE TABLE AS, and a SELECT whose CTE writes, as SELECT, so it is 0 for them. MariaDB reports INSERT ... RETURNING as a result set, so it is 0 there too.

  • columns: null | ResultColumn[]

    The columns of the result, also when it has no rows and with .values() or .raw(). Empty for a statement that returns no rows, such as a plain INSERT. null on SQLite.

  • command: null | string

    The kind of statement. PostgreSQL: the command tag, such as "INSERT" or "CREATE TABLE". SQLite: the first keyword. MySQL: null, because the protocol does not report it.

  • count: number

    The number of rows returned, or the number of rows written when the statement returns none

  • lastInsertRowid: null | string | number | bigint

    The key that an INSERT generated.

    • PostgreSQL: null. Use RETURNING.
    • MySQL: the first AUTO_INCREMENT value of the statement, 0 if there is none. Above Number.MAX_SAFE_INTEGER it is a string, or a BigInt with bigint: true.
    • SQLite: the rowid of the last inserted row, also after a statement that inserts nothing. null for a statement that only reads. A BigInt with safeIntegers: true or bigint: true.
  • statement: null | ResultStatement

    The text, the parameter types and the columns of the statement. null on SQLite.