Skip to content

Commit

Permalink
Add the coalesce function
Browse files Browse the repository at this point in the history
  • Loading branch information
nakamura-to committed Apr 15, 2023
1 parent 825e463 commit 3464c3c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
23 changes: 21 additions & 2 deletions content/en/docs/Reference/Query/QueryDsl/expression.md
Expand Up @@ -16,7 +16,7 @@ This page covers the components of an expression, including declarations, operat
- [Mathematical functions]({{< relref "#mathematical-function" >}})
- [String functions]({{< relref "#string-function" >}})
- [Aggregate functions]({{< relref "#aggregate-function" >}})
- [CASE expressions]({{< relref "#case-expression" >}})
- [Conditional expressions]({{< relref "#conditional-expression" >}})
- [Scalar subqueries]({{< relref "#scalar-subquery" >}})
- [literals]({{< relref "#literal" >}})

Expand Down Expand Up @@ -646,8 +646,27 @@ QueryDsl.from(a).select(min(a.addressId))
select min(t0_.ADDRESS_ID) from ADDRESS as t0_
*/
```
## Conditional expression {#conditional-expression}

## CASE expressions {#case-expression}
The following functions and expressions are available as conditional expressions:

- coalesce
- case

These are defined in `org.komapper.core.dsl.operator`.

### coalesce {#conditional-expression-coalesce}

The following is an example of using the `coalesce` function:

```kotlin
QueryDsl.from(a).select(a.addressId, coalesce(a.street, literal("default")))
/*
select t0_.ADDRESS_ID, coalesce(t0_.STREET, 'default') from ADDRESS as t0_
*/
```

### CASE expressions {#case-expression}

To use a CASE expression, call the `case` function:

Expand Down
24 changes: 22 additions & 2 deletions content/ja/docs/Reference/Query/QueryDsl/expression.md
Expand Up @@ -16,7 +16,7 @@ description: クエリの構成要素を成す式
- [数学関数]({{< relref "#mathematical-function" >}})
- [文字列関数]({{< relref "#string-function" >}})
- [集約関数]({{< relref "#aggregate-function" >}})
- [CASE式]({{< relref "#case-expression" >}})
- [条件式]({{< relref "#conditional-expression" >}})
- [スカラサブクエリ]({{< relref "#scalar-subquery" >}})
- [リテラル]({{< relref "#literal" >}})

Expand Down Expand Up @@ -646,7 +646,27 @@ select min(t0_.ADDRESS_ID) from ADDRESS as t0_
*/
```

## CASE式 {#case-expression}
## 条件式 {#conditional-expression}

次の関数や式が使えます。

- coalesce
- case

これらは`org.komapper.core.dsl.operator`に定義されています。

### coalesce {#conditional-expression-coalesce}

`coalesce`関数を使う例です。

```kotlin
QueryDsl.from(a).select(a.addressId, coalesce(a.street, literal("default")))
/*
select t0_.ADDRESS_ID, coalesce(t0_.STREET, 'default') from ADDRESS as t0_
*/
```

### CASE式 {#case-expression}

CASE式を使うには`case`を呼び出します。

Expand Down

0 comments on commit 3464c3c

Please sign in to comment.