@earth-app/collegedb
    Preparing search index...

    Function buildUpsert

    • Builds an "upsert" using the SQLite/PostgreSQL ON CONFLICT ... DO UPDATE form. On conflict for conflictColumns, the listed update columns (or all non-conflict columns by default) are overwritten with the incoming values via the excluded pseudo-row.

      Parameters

      • table: string

        Target table name

      • values: ColumnValues

        Column to value map for the row to insert

      • conflictColumns: string | string[]

        Column(s) that trigger the conflict resolution

      • options: BuildUpsertOptions = {}

        Upsert modifiers (update subset, RETURNING)

      Returns BuiltQuery

      The parameterized SQL and its bindings

      If no columns, no conflict columns, or an identifier is invalid

      const { sql, bindings } = buildUpsert('kv', { k: 'a', v: '1' }, 'k');
      // sql: INSERT INTO "kv" ("k", "v") VALUES (?, ?) ON CONFLICT ("k") DO UPDATE SET "v" = excluded."v"
      // bindings: ['a', '1']