Skip to content

Commit d752bd1

Browse files
update readme for tuples
1 parent 8c3d135 commit d752bd1

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,12 @@ The `mapColumns` function is used to obtain the results of a column:
399399
val names = database.employees.mapColumns { it.name }
400400
```
401401

402-
Additionally, if we want to select two or more columns, we can change to `mapColumns2` or `mapColumns3`, then we need to wrap our selected columns by `Pair` or `Triple` in the closure, and the function’s return type becomes `List<Pair<C1?, C2?>>` or `List<Triple<C1?, C2?, C3?>>`.
402+
Additionally, if we want to select two or more columns, we just need to wrap our selected columns by `tupleOf` in the closure, and the function’s return type becomes `List<TupleN<C1?, C2?, .. Cn?>>`.
403403

404404
```kotlin
405405
database.employees
406406
.filter { it.departmentId eq 1 }
407-
.mapColumns2 { Pair(it.id, it.name) }
407+
.mapColumns { tupleOf(it.id, it.name) }
408408
.forEach { (id, name) ->
409409
println("$id:$name")
410410
}
@@ -436,12 +436,12 @@ val max = database.employees
436436
.aggregateColumns { max(it.salary) }
437437
```
438438

439-
Also, if we want to aggregate two or more columns, we can change to `aggregateColumns2` or `aggregateColumns3`, then we need to wrap our aggregate expressions by `Pair` or `Triple` in the closure, and the function’s return type becomes `Pair<C1?, C2?>` or `Triple<C1?, C2?, C3?>`. The example below obtains the average and the range of salaries in department 1:
439+
Also, if we want to aggregate two or more columns, we just need to wrap our aggregate expressions by `tupleOf` in the closure, and the function’s return type becomes `TupleN<C1?, C2?, .. Cn?>`. The example below obtains the average and the range of salaries in department 1:
440440

441441
```kotlin
442442
val (avg, diff) = database.employees
443443
.filter { it.departmentId eq 1 }
444-
.aggregateColumns2 { Pair(avg(it.salary), max(it.salary) - min(it.salary)) }
444+
.aggregateColumns { tupleOf(avg(it.salary), max(it.salary) - min(it.salary)) }
445445
```
446446

447447
Generated SQL:

README_cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ val max = database.employees
438438
.aggregateColumns { max(it.salary) }
439439
```
440440

441-
如果你希望同时获取多个聚合结果,只需要在闭包中使用 `tupleOf` 包装我们的这些聚合表达式即可,此时函数的返回值就相应变成了 `Pair<C1?, C2?, .. Cn?>`。下面的例子获取部门 1 中工资的平均值和极差:
441+
如果你希望同时获取多个聚合结果,只需要在闭包中使用 `tupleOf` 包装我们的这些聚合表达式即可,此时函数的返回值就相应变成了 `TupleN<C1?, C2?, .. Cn?>`。下面的例子获取部门 1 中工资的平均值和极差:
442442

443443
```kotlin
444444
val (avg, diff) = database.employees

README_jp.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,12 @@ val employees = database.employees.toCollection(ArrayList())
399399
val names = database.employees.mapColumns { it.name }
400400
```
401401

402-
さらに、2つ以上のカラムを選択したい場合は`mapColumns2``mapColumns3`に変更し、選択したカラムを `Pair` あるいは `Triple` でクロージャでラップする必要があります。この関数の戻り値の型は `List<Pair<C1?, C2?>>``List<Triple<C1?, C2?, C3?>>`になります:
402+
さらに、2つ以上の列を選択する場合は、選択した列をクロージャの `tupleOf` でラップするだけでよく、関数の戻り値の型は `List<TupleN<C1?, C2?, .. Cn?>>` になります:
403403

404404
```kotlin
405405
database.employees
406406
.filter { it.departmentId eq 1 }
407-
.mapColumns2 { Pair(it.id, it.name) }
407+
.mapColumns { tupleOf(it.id, it.name) }
408408
.forEach { (id, name) ->
409409
println("$id:$name")
410410
}
@@ -436,12 +436,12 @@ val max = database.employees
436436
.aggregateColumns { max(it.salary) }
437437
```
438438

439-
また、2つ以上の列を集約したい場合は `aggregateColumns2``aggregateColumns3` に変更し、クロージャ内で `Pair``Triple` で集約式をラップする必要があり、関数の戻り値の型は `Pair<C1?, C2?>``Triple<C1?, C2?, C3?>` となります。以下の例では、第1部門の給与の平均と範囲を求めています。:
439+
また、2つ以上の列を集計する場合は、クロージャー内の `tupleOf` で集計式をラップするだけでよく、関数の戻り値の型は `TupleN<C1?, C2?, .. Cn?>` になります。 以下の例では、部門1の給与の平均と範囲を取得しています。
440440

441441
```kotlin
442442
val (avg, diff) = database.employees
443443
.filter { it.departmentId eq 1 }
444-
.aggregateColumns2 { Pair(avg(it.salary), max(it.salary) - min(it.salary)) }
444+
.aggregateColumns { tupleOf(avg(it.salary), max(it.salary) - min(it.salary)) }
445445
```
446446

447447
生成される SQL文:

0 commit comments

Comments
 (0)