Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(knex): Add includeTriggerModifications for MSSQL support #3355

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/knex/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ export class KnexAdapter<

const { client } = this.db(params).client.config
const returning = RETURNING_CLIENTS.includes(client as string) ? [this.id] : []
const rows: any = await this.db(params).insert(data, returning).catch(errorHandler)
const rows: any = await this.db(params)
.insert(data, returning, { includeTriggerModifications: true })
.catch(errorHandler)
const id = data[this.id] || rows[0][this.id] || rows[0]

if (!id) {
Expand All @@ -256,7 +258,11 @@ export class KnexAdapter<

async _patch(id: null, data: PatchData | Partial<Result>, params?: ServiceParams): Promise<Result[]>
async _patch(id: Id, data: PatchData | Partial<Result>, params?: ServiceParams): Promise<Result>
async _patch(id: NullableId, data: PatchData | Partial<Result>, _params?: ServiceParams): Promise<Result | Result[]>
async _patch(
id: NullableId,
data: PatchData | Partial<Result>,
_params?: ServiceParams
): Promise<Result | Result[]>
async _patch(
id: NullableId,
raw: PatchData | Partial<Result>,
Expand Down Expand Up @@ -285,7 +291,7 @@ export class KnexAdapter<
}
const builder = this.createQuery(updateParams)

await builder.update(data)
await builder.update(data, [], { includeTriggerModifications: true })

const items = await this._findOrGet(null, updateParams)

Expand Down Expand Up @@ -316,7 +322,7 @@ export class KnexAdapter<
return result
}, {})

await this.db(params).update(newObject, '*').where(this.id, id)
await this.db(params).update(newObject, '*', { includeTriggerModifications: true }).where(this.id, id)

return this._get(id, params)
}
Expand All @@ -339,7 +345,7 @@ export class KnexAdapter<
// build up the knex query out of the query params
this.knexify(q, query)

await q.del().catch(errorHandler)
await q.delete([], { includeTriggerModifications: true }).catch(errorHandler)

if (id !== null) {
if (items.length === 1) {
Expand Down
Loading