Skip to content

Commit

Permalink
Merge pull request #382 from geekbeast/fix/duplicates-and-stats
Browse files Browse the repository at this point in the history
Additional Postgres Utility Functions
  • Loading branch information
geekbeast authored Sep 13, 2023
2 parents 58167c7 + c172adf commit 4e56d39
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ package com.geekbeast.rhizome
/**
* @author Drew Bailey &lt;[email protected]&gt;
*/
class KotlinDelegatedStringSet( strings: Set<String> ): Set<String> by strings
class KotlinDelegatedStringSet(strings: Set<String>) : Set<String> by strings {
override fun equals(other: Any?): Boolean {

return if (other !is Set<*> ) {
false
} else {
this.size == other.size && this.containsAll(other)
}
}
}

0 comments on commit 4e56d39

Please sign in to comment.