-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Supporting all types array aggregations (#266)
* Fix: Supporting all types array aggregations
- Loading branch information
1 parent
470918a
commit de18245
Showing
5 changed files
with
75 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.foo | ||
|
||
import java.sql.PreparedStatement | ||
import java.sql.ResultSet | ||
import kotlin.Array | ||
import kotlin.Int | ||
import kotlin.Long | ||
import kotlin.String | ||
import kotlin.Unit | ||
import norm.ParamSetter | ||
import norm.Query | ||
import norm.RowMapper | ||
|
||
public class FooParams() | ||
|
||
public class FooParamSetter : ParamSetter<FooParams> { | ||
public override fun map(ps: PreparedStatement, params: FooParams): Unit { | ||
} | ||
} | ||
|
||
public class FooRowMapper : RowMapper<FooResult> { | ||
public override fun map(rs: ResultSet): FooResult = FooResult( | ||
ids = rs.getArray("ids")?.array as kotlin.Array<kotlin.Int>?, | ||
docids = rs.getArray("docids")?.array as kotlin.Array<kotlin.Long>?, | ||
arrTypes = rs.getArray("arr_types")?.array as kotlin.Array<kotlin.String>?, | ||
strTypes = rs.getObject("str_types") as kotlin.String?) | ||
} | ||
|
||
public class FooQuery : Query<FooParams, FooResult> { | ||
public override val sql: String = | ||
"SELECT ARRAY_AGG(id) AS ids, ARRAY_AGG(documentId) AS docIds, ARRAY_AGG(type) AS arr_types, STRING_AGG(type, '-') AS str_types FROM requests GROUP BY type" | ||
|
||
public override val mapper: RowMapper<FooResult> = FooRowMapper() | ||
|
||
public override val paramSetter: ParamSetter<FooParams> = FooParamSetter() | ||
} | ||
|
||
public data class FooResult( | ||
public val ids: Array<Int>?, | ||
public val docids: Array<Long>?, | ||
public val arrTypes: Array<String>?, | ||
public val strTypes: String? | ||
) |
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