Skip to content

UPSERT

Choose a tag to compare

@LCluber LCluber released this 24 Mar 20:39
· 49 commits to main since this release
  • Add UPSERT functionality using PostgreSQL's INSERT ... ON CONFLICT ... DO UPDATE syntax:
    • New query.upsert() method generates upsert queries with configurable conflict targets
    • Supports single or multiple column conflict targets (e.g., 'id' or ['email', 'username'])
    • Properties with both INSERT and UPDATE operations are automatically included in upsert
    • Optionally includes consumerId and consumerName for history tracking
    • Supports RETURNING clause to retrieve updated/inserted row IDs
  • Add upsert() Express middleware for handling upsert operations:
    • Expects rows and conflictTarget in request body
    • Returns upserted rows with IDs in res.locals.rows
    • Supports chunking for bulk operations
  • Add convenience Express substack middlewares:
    • upsertArraySubstack: Returns [normalizeArray, validateArray, upsert] middleware chain
    • upsertOneSubstack: Returns [normalizeOne, validateOne, upsert] middleware chain