From f28840805bf6caff3f63dbc82f265c99e770c18b Mon Sep 17 00:00:00 2001 From: vince Date: Sat, 9 Sep 2023 20:01:38 +0800 Subject: [PATCH] array_position impl --- .../org/ktorm/support/postgresql/Functions.kt | 93 +++++++------------ 1 file changed, 33 insertions(+), 60 deletions(-) diff --git a/ktorm-support-postgresql/src/main/kotlin/org/ktorm/support/postgresql/Functions.kt b/ktorm-support-postgresql/src/main/kotlin/org/ktorm/support/postgresql/Functions.kt index c26e1c25..8d0e7dd2 100644 --- a/ktorm-support-postgresql/src/main/kotlin/org/ktorm/support/postgresql/Functions.kt +++ b/ktorm-support-postgresql/src/main/kotlin/org/ktorm/support/postgresql/Functions.kt @@ -29,16 +29,7 @@ import org.ktorm.schema.* public fun arrayPosition( array: ColumnDeclaring, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - // array_position(array, value[, offset]) - return FunctionExpression( - functionName = "array_position", - arguments = listOfNotNull( - array.asExpression(), - value.asExpression(), - offset?.let { ArgumentExpression(it, IntSqlType) } - ), - sqlType = IntSqlType - ) + return arrayPositionImpl(array, value, offset) } /** @@ -50,7 +41,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: Short, offset: Int? = null ): FunctionExpression { - return arrayPosition(array, ArgumentExpression(value, ShortSqlType), offset) + return arrayPositionImpl(array, ArgumentExpression(value, ShortSqlType), offset) } /** @@ -62,7 +53,7 @@ public fun arrayPosition( public fun arrayPosition( array: ShortArray, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - return arrayPosition(ArgumentExpression(array, ShortArraySqlType), value, offset) + return arrayPositionImpl(ArgumentExpression(array, ShortArraySqlType), value, offset) } /** @@ -74,16 +65,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - // array_position(array, value[, offset]) - return FunctionExpression( - functionName = "array_position", - arguments = listOfNotNull( - array.asExpression(), - value.asExpression(), - offset?.let { ArgumentExpression(it, IntSqlType) } - ), - sqlType = IntSqlType - ) + return arrayPositionImpl(array, value, offset) } /** @@ -95,7 +77,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: Int, offset: Int? = null ): FunctionExpression { - return arrayPosition(array, ArgumentExpression(value, IntSqlType), offset) + return arrayPositionImpl(array, ArgumentExpression(value, IntSqlType), offset) } /** @@ -107,7 +89,7 @@ public fun arrayPosition( public fun arrayPosition( array: IntArray, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - return arrayPosition(ArgumentExpression(array, IntArraySqlType), value, offset) + return arrayPositionImpl(ArgumentExpression(array, IntArraySqlType), value, offset) } /** @@ -119,16 +101,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - // array_position(array, value[, offset]) - return FunctionExpression( - functionName = "array_position", - arguments = listOfNotNull( - array.asExpression(), - value.asExpression(), - offset?.let { ArgumentExpression(it, IntSqlType) } - ), - sqlType = IntSqlType - ) + return arrayPositionImpl(array, value, offset) } /** @@ -140,7 +113,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: Long, offset: Int? = null ): FunctionExpression { - return arrayPosition(array, ArgumentExpression(value, LongSqlType), offset) + return arrayPositionImpl(array, ArgumentExpression(value, LongSqlType), offset) } /** @@ -152,7 +125,7 @@ public fun arrayPosition( public fun arrayPosition( array: LongArray, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - return arrayPosition(ArgumentExpression(array, LongArraySqlType), value, offset) + return arrayPositionImpl(ArgumentExpression(array, LongArraySqlType), value, offset) } /** @@ -164,16 +137,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - // array_position(array, value[, offset]) - return FunctionExpression( - functionName = "array_position", - arguments = listOfNotNull( - array.asExpression(), - value.asExpression(), - offset?.let { ArgumentExpression(it, IntSqlType) } - ), - sqlType = IntSqlType - ) + return arrayPositionImpl(array, value, offset) } /** @@ -185,7 +149,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: Boolean, offset: Int? = null ): FunctionExpression { - return arrayPosition(array, ArgumentExpression(value, BooleanSqlType), offset) + return arrayPositionImpl(array, ArgumentExpression(value, BooleanSqlType), offset) } /** @@ -197,7 +161,7 @@ public fun arrayPosition( public fun arrayPosition( array: BooleanArray, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - return arrayPosition(ArgumentExpression(array, BooleanArraySqlType), value, offset) + return arrayPositionImpl(ArgumentExpression(array, BooleanArraySqlType), value, offset) } /** @@ -209,16 +173,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - // array_position(array, value[, offset]) - return FunctionExpression( - functionName = "array_position", - arguments = listOfNotNull( - array.asExpression(), - value.asExpression(), - offset?.let { ArgumentExpression(it, IntSqlType) } - ), - sqlType = IntSqlType - ) + return arrayPositionImpl(array, value, offset) } /** @@ -230,7 +185,7 @@ public fun arrayPosition( public fun arrayPosition( array: ColumnDeclaring, value: String, offset: Int? = null ): FunctionExpression { - return arrayPosition(array, ArgumentExpression(value, VarcharSqlType), offset) + return arrayPositionImpl(array, ArgumentExpression(value, VarcharSqlType), offset) } /** @@ -242,5 +197,23 @@ public fun arrayPosition( public fun arrayPosition( array: TextArray, value: ColumnDeclaring, offset: Int? = null ): FunctionExpression { - return arrayPosition(ArgumentExpression(array, TextArraySqlType), value, offset) + return arrayPositionImpl(ArgumentExpression(array, TextArraySqlType), value, offset) +} + +/** + * array_position implementation. + */ +private fun arrayPositionImpl( + array: ColumnDeclaring, value: ColumnDeclaring, offset: Int? = null +): FunctionExpression { + // array_position(array, value[, offset]) + return FunctionExpression( + functionName = "array_position", + arguments = listOfNotNull( + array.asExpression(), + value.asExpression(), + offset?.let { ArgumentExpression(it, IntSqlType) } + ), + sqlType = IntSqlType + ) }