Function insert

  • Run an insert query on the database.

    Type Parameters

    Parameters

    • conn: PoolClient

      The connection to the database

    • table: string

      The table to insert into

    • data: T

      The data to insert

    • Optionalconflict: (keyof T)[]

      The columns to check for conflicts, if any

    Returns Promise<V>

    The inserted row

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