Skip to content

Added custom sqlite types support#1741

Merged
AndreiKingsley merged 7 commits intomasterfrom
custom_sqlite_types
Apr 12, 2026
Merged

Added custom sqlite types support#1741
AndreiKingsley merged 7 commits intomasterfrom
custom_sqlite_types

Conversation

@AndreiKingsley
Copy link
Copy Markdown
Collaborator

@AndreiKingsley AndreiKingsley commented Mar 12, 2026

Closes #964

get() = "org.sqlite.JDBC"

override fun getExpectedJdbcType(tableColumnMetadata: TableColumnMetadata): KType =
customTypesMap[tableColumnMetadata.sqlTypeName] ?: super.getExpectedJdbcType(tableColumnMetadata)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if sqlTypeName is enough to differentiate the right type.

Also, take nullability into account.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

For now, I believe sqlTypeName is OK.
However, we should improve this mechanism in future. This will require us to research use cases in depth.

@AndreiKingsley
Copy link
Copy Markdown
Collaborator Author

Requires #1735

@AndreiKingsley AndreiKingsley requested a review from zaleslaw March 16, 2026 13:10
@AndreiKingsley AndreiKingsley changed the title Custom sqlite types Added custom sqlite types support Mar 16, 2026
@AndreiKingsley AndreiKingsley marked this pull request as ready for review March 27, 2026 09:57
@zaleslaw
Copy link
Copy Markdown
Collaborator

The problem is clear, your proposal is also promisable.
I have a couple of question:

  • is this behaviour typical only for SQLite database or we could benefit with other SQL databases also
  • why it could not be implemented through getExpectedJdbcType, where is a bottleneck?

@AndreiKingsley
Copy link
Copy Markdown
Collaborator Author

AndreiKingsley commented Apr 8, 2026

@zaleslaw

  1. For now, this issue is most relevant to SQLite. The problem with SQLite is that the type defined by the user and even built-in types may not match the actual values from JDBC.

    In theory, PostgreSQL might have a similar mechanism, since it also allows for the creation of custom types. However, the rules there are slightly stricter, and our built-in getExpectedJdbcType mechanism might be sufficient. With SQLite, on the other hand, there are definitely cases where it won’t be possible to determine the type using JDBC, as described in the issue.

    In fact it needs research, for sure!

  2. getExpectedJdbcType compute type only from column metadata — as and shown in the issue, it can be exactly the same for columns with the different types.

DriverManager.getConnection(dbConfig.url, dbConfig.user, dbConfig.password)
}

public companion object {
Copy link
Copy Markdown
Collaborator

@Jolanrensen Jolanrensen Apr 10, 2026

Choose a reason for hiding this comment

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

A fun trick I just learned. If you make Sqlite open, you can make the companion object be the default itself, like companion object : Sqlite() {}
This means users can specify both Sqlite and Sqlite.withCustomTypes(customTypes). Not sure if you like that :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh, seems great!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But I am not sure if this is actually good here, need a research of use-cases.

#1797

@AndreiKingsley AndreiKingsley merged commit 8df560c into master Apr 12, 2026
4 checks passed
@AndreiKingsley AndreiKingsley deleted the custom_sqlite_types branch April 12, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClassCast exception when reading from specific sqlite db

3 participants