Skip to content

postgrelize / MergeOptions

Interface: MergeOptions<T> ​

Defined in: src/model/merge-options.ts:62

postgrelize extension

Options of Model.merge, which runs a MERGE statement. PostgreSQL extension. PostgreSQL 15+ (RETURNING: 17+).

Rows of the model table are the target; source rows or a subquery are the source.

See ​

Model.merge

Example ​

ts
const opts: MergeOptions<Product> = {
  source: [{ sku: 'a1', price: 10 }],
  on: { sku: col('source.sku') },
  whenMatched: { update: { price: col('source.price') } },
  whenNotMatched: { insert: true },
};

Type Parameters ​

T ​

T

Properties ​

as? ​

readonly optional as?: string

Defined in: src/model/merge-options.ts:67

Alias of the source relation.

Default Value ​

ts
'source'

on ​

readonly on: unknown

Defined in: src/model/merge-options.ts:69

Join condition between target (model alias) and source (col('source.attr')).


source ​

readonly source: Subquery | readonly Readonly<Record<string, unknown>>[]

Defined in: src/model/merge-options.ts:64

Source rows (plain objects) or a subquery.


whenMatched? ​

readonly optional whenMatched?: MergeMatchedAction<T> | readonly MergeMatchedAction<T>[]

Defined in: src/model/merge-options.ts:71

Actions for matched rows, applied in order.


whenNotMatched? ​

readonly optional whenNotMatched?: MergeInsertAction<T> | readonly MergeInsertAction<T>[]

Defined in: src/model/merge-options.ts:73

Actions for source rows without a target row.


whenNotMatchedBySource? ​

readonly optional whenNotMatchedBySource?: MergeMatchedAction<T> | readonly MergeMatchedAction<T>[]

Defined in: src/model/merge-options.ts:75

Actions for target rows without a source row (PostgreSQL 17+).

Released under the MIT License.