Skip to content

Commit

Permalink
boolean array sql type
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlauvlwj committed Sep 9, 2023
1 parent cb41236 commit 04d66be
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,34 @@ public object DoubleArraySqlType : SqlType<DoubleArray>(Types.ARRAY, "double[]")
}
}

/**
* Define a column typed [BooleanArraySqlType].
*/
public fun BaseTable<*>.booleanArray(name: String): Column<BooleanArray> {
return registerColumn(name, BooleanArraySqlType)
}

/**
* [SqlType] implementation represents PostgreSQL `boolean[]` type.
*/
public object BooleanArraySqlType : SqlType<BooleanArray>(Types.ARRAY, "boolean[]") {

override fun doSetParameter(ps: PreparedStatement, index: Int, parameter: BooleanArray) {
ps.setObject(index, parameter)
}

@Suppress("UNCHECKED_CAST")
override fun doGetResult(rs: ResultSet, index: Int): BooleanArray? {
val sqlArray = rs.getArray(index) ?: return null
try {
val objectArray = sqlArray.array as Array<Any>?
return objectArray?.map { it as Boolean }?.toBooleanArray()
} finally {
sqlArray.free()
}
}
}

/**
* Represent values of PostgreSQL `text[]` SQL type.
*/
Expand Down

0 comments on commit 04d66be

Please sign in to comment.