Function update

  • Run an update query on the database.

    Type Parameters

    • T extends ObjectAny
    • Data extends Record<string, unknown>
    • V extends Record<string, unknown>

    Parameters

    • conn: PoolClient

      The connection to the database

    • table: string

      The table to update

    • where: { [K in string | number | symbol]: T[K] }

      The where clause

    • data: Data

      The data to update

    Returns Promise<V>

    The updated row

    using conn = await pool.connect();
    const res = await update(conn, "users", { id: 1 }, { name: "John Doe" });
    • If for some reason the query fails and the row does not exist