Skip to content

Commit

Permalink
Add functions to handle date arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Tamayo committed Sep 1, 2023
1 parent 58167c7 commit b48409a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/kotlin/com/geekbeast/postgres/PostgresArrays.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import java.sql.SQLException
import java.util.UUID
import com.geekbeast.postgres.PostgresDatatype
import java.sql.Connection
import java.sql.Date
import java.sql.ResultSet
import java.time.LocalDate
import java.util.stream.Stream

/**
Expand Down Expand Up @@ -120,6 +122,24 @@ object PostgresArrays {
return connection.createArrayOf(PostgresDatatype.SMALLINT.sql(), values.toTypedArray())
}

@JvmStatic
@Throws(SQLException::class)
fun createDateArray(connection: Connection, values: Stream<LocalDate>): java.sql.Array {
return connection.createArrayOf(PostgresDatatype.DATE.sql(), values.toArray())
}

@JvmStatic
@Throws(SQLException::class)
fun createDateArray(connection: Connection, vararg value: LocalDate): java.sql.Array {
return connection.createArrayOf(PostgresDatatype.DATE.sql(), value)
}

@JvmStatic
@Throws(SQLException::class)
fun createDateArray(connection: Connection, values: Collection<LocalDate>): java.sql.Array {
return connection.createArrayOf(PostgresDatatype.DATE.sql(), values.toTypedArray())
}

@JvmStatic
@Throws(SQLException::class)
fun getTextArray(rs: ResultSet, column: String): Array<String> {
Expand All @@ -144,6 +164,12 @@ object PostgresArrays {
return rs.getArray(column).array as Array<Array<UUID>>
}

@JvmStatic
@Throws(SQLException::class)
fun getDateArray(rs: ResultSet, column: String): List<LocalDate> {
return (rs.getArray(column).array as Array<Date>).map { it.toLocalDate() }
}

@JvmStatic
@Throws(SQLException::class)
fun getUuidArray(rs: ResultSet, column: String): Array<UUID>? {
Expand Down

0 comments on commit b48409a

Please sign in to comment.