-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0acc7a4
commit 8bd213e
Showing
8 changed files
with
92 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
site/docs/examples/merge/0010-update-target-column-based-on-existence-of-source-row.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const updateTargetColumnBasedOnExistenceOfSourceRow = `const result = await db | ||
.mergeInto('person as target') | ||
.using('pet as source', 'source.owner_id', 'target.id') | ||
.whenMatchedAnd('target.has_pets', '!=', 'Y') | ||
.thenUpdateSet({ has_pets: 'Y' }) | ||
.whenNotMatchedBySourceAnd('target.has_pets', '=', 'Y') | ||
.thenUpdateSet({ has_pets: 'N' }) | ||
.executeTakeFirstOrThrow() | ||
console.log(result.numChangedRows)` |
36 changes: 36 additions & 0 deletions
36
...s/examples/merge/0010-update-target-column-based-on-existence-of-source-row.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: 'Update target column based on existence of source row' | ||
--- | ||
|
||
# Update target column based on existence of source row | ||
|
||
Update a target column based on the existence of a source row: | ||
|
||
import { | ||
Playground, | ||
exampleSetup, | ||
} from '../../../src/components/Playground' | ||
|
||
import { | ||
updateTargetColumnBasedOnExistenceOfSourceRow | ||
} from './0010-update-target-column-based-on-existence-of-source-row' | ||
|
||
<div style={{ marginBottom: '1em' }}> | ||
<Playground code={updateTargetColumnBasedOnExistenceOfSourceRow} setupCode={exampleSetup} /> | ||
</div> | ||
|
||
:::info[More examples] | ||
The API documentation is packed with examples. The API docs are hosted [here](https://kysely-org.github.io/kysely-apidoc/), | ||
but you can access the same documentation by hovering over functions/methods/classes in your IDE. The examples are always | ||
just one hover away! | ||
|
||
For example, check out these sections: | ||
- [mergeInto method](https://kysely-org.github.io/kysely-apidoc/classes/Kysely.html#mergeInto) | ||
- [using method](https://kysely-org.github.io/kysely-apidoc/classes/MergeQueryBuilder.html#using) | ||
- [whenMatched method](https://kysely-org.github.io/kysely-apidoc/classes/WheneableMergeQueryBuilder.html#whenMatched) | ||
- [thenUpdateSet method](https://kysely-org.github.io/kysely-apidoc/classes/MatchedThenableMergeQueryBuilder.html#thenUpdateSet) | ||
- [thenDelete method](https://kysely-org.github.io/kysely-apidoc/classes/MatchedThenableMergeQueryBuilder.html#thenDelete) | ||
- [thenDoNothing method](https://kysely-org.github.io/kysely-apidoc/classes/MatchedThenableMergeQueryBuilder.html#thenDoNothing) | ||
- [whenNotMatched method](https://kysely-org.github.io/kysely-apidoc/classes/WheneableMergeQueryBuilder.html#whenNotMatched) | ||
- [thenInsertValues method](https://kysely-org.github.io/kysely-apidoc/classes/NotMatchedThenableMergeQueryBuilder.html#thenInsertValues) | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"label": "MERGE", | ||
"position": 7, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Short and simple examples of how to write MERGE queries." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters