Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support SqlDelight modules to implement PostgreSql extensions #5677

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

Merged
merged 2 commits into from
May 13, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.SHORT
import com.squareup.kotlinpoet.STRING
import com.squareup.kotlinpoet.TypeName

internal enum class PostgreSqlType(override val javaType: TypeName) : DialectType {
enum class PostgreSqlType(override val javaType: TypeName) : DialectType {
SMALL_INT(SHORT),
INTEGER(INT),
BIG_INT(LONG),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.asTypeName

class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeResolver by parentResolver {
open class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeResolver by parentResolver {
override fun definitionType(typeName: SqlTypeName): IntermediateType = with(typeName) {
check(this is PostgreSqlTypeName)
val type = IntermediateType(
Expand Down Expand Up @@ -250,6 +250,11 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
}
}

// dialects or modules would need to extend this if they add types that use operators in binaryExprChildTypesResolvingToBool
protected open fun booleanBinaryExprTypes(): Array<DialectType> {
return booleanBinaryExprTypes
}

private fun SqlExpr.postgreSqlType(): IntermediateType = when (this) {
is SqlIsExpr -> IntermediateType(BOOLEAN)
is SqlBinaryExpr -> {
Expand All @@ -262,23 +267,7 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
(this is SqlBinaryAddExpr || this is SqlBinaryMultExpr || this is SqlBinaryPipeExpr) &&
exprListNullability.any { it }
},
SMALL_INT,
PostgreSqlType.INTEGER,
INTEGER,
BIG_INT,
REAL,
PostgreSqlType.NUMERIC,
TEXT,
BLOB,
BOOLEAN,
DATE,
PostgreSqlType.UUID,
PostgreSqlType.INTERVAL,
PostgreSqlType.TIMESTAMP_TIMEZONE,
PostgreSqlType.TIMESTAMP,
PostgreSqlType.TIME,
PostgreSqlType.JSON,
PostgreSqlType.TSVECTOR,
typeOrder = booleanBinaryExprTypes(),
)
}
}
Expand Down Expand Up @@ -343,6 +332,26 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
}

companion object {

private val booleanBinaryExprTypes: Array<DialectType> = arrayOf(
SMALL_INT,
PostgreSqlType.INTEGER,
INTEGER,
BIG_INT,
REAL,
PostgreSqlType.NUMERIC,
TEXT,
BLOB,
DATE,
PostgreSqlType.UUID,
PostgreSqlType.INTERVAL,
PostgreSqlType.TIMESTAMP_TIMEZONE,
PostgreSqlType.TIMESTAMP,
PostgreSqlType.TIME,
PostgreSqlType.JSON,
PostgreSqlType.TSVECTOR,
BOOLEAN, // is last as expected that boolean expression resolve to boolean
)
private val binaryExprChildTypesResolvingToBool = TokenSet.create(
SqlTypes.EQ,
SqlTypes.EQ2,
Expand Down