Skip to content

Commit

Permalink
array_position impl
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlauvlwj committed Sep 9, 2023
1 parent 0ce6d32 commit f288408
Showing 1 changed file with 33 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@ import org.ktorm.schema.*
public fun arrayPosition(
array: ColumnDeclaring<ShortArray>, value: ColumnDeclaring<Short>, offset: Int? = null
): FunctionExpression<Int> {
// 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)
}

/**
Expand All @@ -50,7 +41,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<ShortArray>, value: Short, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(array, ArgumentExpression(value, ShortSqlType), offset)
return arrayPositionImpl(array, ArgumentExpression(value, ShortSqlType), offset)
}

/**
Expand All @@ -62,7 +53,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ShortArray, value: ColumnDeclaring<Short>, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(ArgumentExpression(array, ShortArraySqlType), value, offset)
return arrayPositionImpl(ArgumentExpression(array, ShortArraySqlType), value, offset)
}

/**
Expand All @@ -74,16 +65,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<IntArray>, value: ColumnDeclaring<Int>, offset: Int? = null
): FunctionExpression<Int> {
// 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)
}

/**
Expand All @@ -95,7 +77,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<IntArray>, value: Int, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(array, ArgumentExpression(value, IntSqlType), offset)
return arrayPositionImpl(array, ArgumentExpression(value, IntSqlType), offset)
}

/**
Expand All @@ -107,7 +89,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: IntArray, value: ColumnDeclaring<Int>, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(ArgumentExpression(array, IntArraySqlType), value, offset)
return arrayPositionImpl(ArgumentExpression(array, IntArraySqlType), value, offset)
}

/**
Expand All @@ -119,16 +101,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<LongArray>, value: ColumnDeclaring<Long>, offset: Int? = null
): FunctionExpression<Int> {
// 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)
}

/**
Expand All @@ -140,7 +113,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<LongArray>, value: Long, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(array, ArgumentExpression(value, LongSqlType), offset)
return arrayPositionImpl(array, ArgumentExpression(value, LongSqlType), offset)
}

/**
Expand All @@ -152,7 +125,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: LongArray, value: ColumnDeclaring<Long>, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(ArgumentExpression(array, LongArraySqlType), value, offset)
return arrayPositionImpl(ArgumentExpression(array, LongArraySqlType), value, offset)
}

/**
Expand All @@ -164,16 +137,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<BooleanArray>, value: ColumnDeclaring<Boolean>, offset: Int? = null
): FunctionExpression<Int> {
// 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)
}

/**
Expand All @@ -185,7 +149,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<BooleanArray>, value: Boolean, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(array, ArgumentExpression(value, BooleanSqlType), offset)
return arrayPositionImpl(array, ArgumentExpression(value, BooleanSqlType), offset)
}

/**
Expand All @@ -197,7 +161,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: BooleanArray, value: ColumnDeclaring<Boolean>, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(ArgumentExpression(array, BooleanArraySqlType), value, offset)
return arrayPositionImpl(ArgumentExpression(array, BooleanArraySqlType), value, offset)
}

/**
Expand All @@ -209,16 +173,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<TextArray>, value: ColumnDeclaring<String>, offset: Int? = null
): FunctionExpression<Int> {
// 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)
}

/**
Expand All @@ -230,7 +185,7 @@ public fun arrayPosition(
public fun arrayPosition(
array: ColumnDeclaring<TextArray>, value: String, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(array, ArgumentExpression(value, VarcharSqlType), offset)
return arrayPositionImpl(array, ArgumentExpression(value, VarcharSqlType), offset)
}

/**
Expand All @@ -242,5 +197,23 @@ public fun arrayPosition(
public fun arrayPosition(
array: TextArray, value: ColumnDeclaring<String>, offset: Int? = null
): FunctionExpression<Int> {
return arrayPosition(ArgumentExpression(array, TextArraySqlType), value, offset)
return arrayPositionImpl(ArgumentExpression(array, TextArraySqlType), value, offset)
}

/**
* array_position implementation.
*/
private fun <T : Any, S : Any> arrayPositionImpl(
array: ColumnDeclaring<T>, value: ColumnDeclaring<S>, offset: Int? = null
): FunctionExpression<Int> {
// array_position(array, value[, offset])
return FunctionExpression(
functionName = "array_position",
arguments = listOfNotNull(
array.asExpression(),
value.asExpression(),
offset?.let { ArgumentExpression(it, IntSqlType) }
),
sqlType = IntSqlType
)
}

0 comments on commit f288408

Please sign in to comment.