Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getObject method supports automatic filling of the actual type. #3401

Merged
merged 2 commits into from Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -61,9 +61,10 @@ internal enum class MySqlType(override val javaType: TypeName) : DialectType {
return CodeBlock.of(
when (this) {
TINY_INT, TINY_INT_BOOL, SMALL_INT, INTEGER, BIG_INT, BIT -> "$cursorName.getLong($columnIndex)"
DATE, TIME, DATETIME, TIMESTAMP -> "$cursorName.getObject($columnIndex)"
DATE, TIME, DATETIME, TIMESTAMP -> "$cursorName.getObject<%T>($columnIndex)"
NUMERIC -> "$cursorName.getBigDecimal($columnIndex)"
},
javaType,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose CodeBlock.of() is fine with extra parameters if they never get used - if tests pass its probably fine

)
}
}
Expand Up @@ -46,9 +46,10 @@ internal enum class PostgreSqlType(override val javaType: TypeName) : DialectTyp
return CodeBlock.of(
when (this) {
SMALL_INT, INTEGER, BIG_INT -> "$cursorName.getLong($columnIndex)"
DATE, TIME, TIMESTAMP, TIMESTAMP_TIMEZONE, INTERVAL, UUID -> "$cursorName.getObject($columnIndex)"
DATE, TIME, TIMESTAMP, TIMESTAMP_TIMEZONE, INTERVAL, UUID -> "$cursorName.getObject<%T>($columnIndex)"
NUMERIC -> "$cursorName.getBigDecimal($columnIndex)"
},
javaType,
)
}
}
Expand Up @@ -592,6 +592,8 @@ class SelectQueryFunctionTest {

val file = FixtureCompiler.parseSql(
"""
|import kotlinx.datetime.Instant;
|
|CREATE TABLE data (
| boolean0 BOOLEAN NOT NULL,
| boolean1 BOOLEAN,
Expand All @@ -616,7 +618,9 @@ class SelectQueryFunctionTest {
| bigint0 BIGINT NOT NULL,
| bigint1 BIGINT,
| bigint2 BIGINT AS kotlin.String NOT NULL,
| bigint3 BIGINT AS kotlin.String
| bigint3 BIGINT AS kotlin.String,
| timestamp0 TIMESTAMP AS Instant NOT NULL,
| timestamp1 TIMESTAMP AS Instant
|);
|
|selectData:
Expand Down Expand Up @@ -657,6 +661,8 @@ class SelectQueryFunctionTest {
| bigint1: kotlin.Long?,
| bigint2: kotlin.String,
| bigint3: kotlin.String?,
| timestamp0: kotlinx.datetime.Instant,
| timestamp1: kotlinx.datetime.Instant?,
|) -> T): app.cash.sqldelight.Query<T> = app.cash.sqldelight.Query(${query.id}, arrayOf("data"), driver, "Test.sq", "selectData", ""${'"'}
||SELECT *
||FROM data
Expand Down Expand Up @@ -686,7 +692,9 @@ class SelectQueryFunctionTest {
| cursor.getLong(20)!!,
| cursor.getLong(21),
| data_Adapter.bigint2Adapter.decode(cursor.getLong(22)!!),
| cursor.getLong(23)?.let { data_Adapter.bigint3Adapter.decode(it) }
| cursor.getLong(23)?.let { data_Adapter.bigint3Adapter.decode(it) },
| data_Adapter.timestamp0Adapter.decode(cursor.getObject<java.time.OffsetDateTime>(24)!!),
| cursor.getObject<java.time.OffsetDateTime>(25)?.let { data_Adapter.timestamp1Adapter.decode(it) }
| )
|}
|
Expand All @@ -699,6 +707,8 @@ class SelectQueryFunctionTest {

val file = FixtureCompiler.parseSql(
"""
|import kotlinx.datetime.Instant;
|
|CREATE TABLE data (
| intArray SMALLINT[],
| smallint0 SMALLINT NOT NULL,
Expand All @@ -713,7 +723,9 @@ class SelectQueryFunctionTest {
| bigint1 BIGINT,
| bigint2 BIGINT AS kotlin.String NOT NULL,
| bigint3 BIGINT AS kotlin.String,
| uuid UUID NOT NULL
| uuid UUID NOT NULL,
| timestamp0 TIMESTAMP AS Instant NOT NULL,
| timestamp1 TIMESTAMP AS Instant
|);
|
|selectData:
Expand Down Expand Up @@ -744,6 +756,8 @@ class SelectQueryFunctionTest {
| bigint2: kotlin.String,
| bigint3: kotlin.String?,
| uuid: java.util.UUID,
| timestamp0: kotlinx.datetime.Instant,
| timestamp1: kotlinx.datetime.Instant?,
|) -> T): app.cash.sqldelight.Query<T> = app.cash.sqldelight.Query(${query.id}, arrayOf("data"), driver, "Test.sq", "selectData", ""${'"'}
||SELECT *
||FROM data
Expand All @@ -763,7 +777,9 @@ class SelectQueryFunctionTest {
| cursor.getLong(10),
| data_Adapter.bigint2Adapter.decode(cursor.getLong(11)!!),
| cursor.getLong(12)?.let { data_Adapter.bigint3Adapter.decode(it) },
| cursor.getObject(13)!!
| cursor.getObject<java.util.UUID>(13)!!,
| data_Adapter.timestamp0Adapter.decode(cursor.getObject<java.time.LocalDateTime>(14)!!),
| cursor.getObject<java.time.LocalDateTime>(15)?.let { data_Adapter.timestamp1Adapter.decode(it) }
| )
|}
|
Expand Down