-
Notifications
You must be signed in to change notification settings - Fork 279
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
5b79e88
commit cb4914a
Showing
16 changed files
with
241 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ | |
"script:copy-interface-doc": "node scripts/copy-interface-documentation.js", | ||
"script:add-deno-type-references": "node scripts/add-deno-type-references.js", | ||
"script:align-site-version": "node scripts/align-site-version.js", | ||
"script:generate-site-examples": "node scripts/generate-site-examples.js", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"author": "Sami Koskimäki <[email protected]>", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const sourceRowExistence = `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)` |
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: 'Source row existence' | ||
--- | ||
|
||
# Source row existence | ||
|
||
Update a target column based on the existence of a source row: | ||
|
||
import { | ||
Playground, | ||
exampleSetup, | ||
} from '../../../src/components/Playground' | ||
|
||
import { | ||
sourceRowExistence | ||
} from './0010-source-row-existence' | ||
|
||
<div style={{ marginBottom: '1em' }}> | ||
<Playground code={sourceRowExistence} 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,23 @@ | ||
export const temporaryChangesTable = `const result = await db | ||
.mergeInto("wine as target") | ||
.using( | ||
"wine_stock_change as source", | ||
"source.wine_name", | ||
"target.name", | ||
) | ||
.whenNotMatchedAnd("source.stock_delta", ">", 0) | ||
.thenInsertValues(({ ref }) => ({ | ||
name: ref("source.wine_name"), | ||
stock: ref("source.stock_delta"), | ||
})) | ||
.whenMatchedAnd( | ||
(eb) => eb("target.stock", "+", eb.ref("source.stock_delta")), | ||
">", | ||
0, | ||
) | ||
.thenUpdateSet("stock", (eb) => | ||
eb("target.stock", "+", eb.ref("source.stock_delta")), | ||
) | ||
.whenMatched() | ||
.thenDelete() | ||
.executeTakeFirstOrThrow()` |
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: 'Temporary changes table' | ||
--- | ||
|
||
# Temporary changes table | ||
|
||
Merge new entries from a temporary changes table: | ||
|
||
import { | ||
Playground, | ||
exampleSetup, | ||
} from '../../../src/components/Playground' | ||
|
||
import { | ||
temporaryChangesTable | ||
} from './0020-temporary-changes-table' | ||
|
||
<div style={{ marginBottom: '1em' }}> | ||
<Playground code={temporaryChangesTable} 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ title: 'Distinct' | |
|
||
# Distinct | ||
|
||
### Examples | ||
|
||
import { | ||
Playground, | ||
exampleSetup, | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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