Skip to content

Commit

Permalink
removed if
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo committed Nov 19, 2024
1 parent 11fe78e commit 3cd56bd
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/main/kotlin/crablet/postgres/CrabletEventsAppender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,17 @@ class CrabletEventsAppender(private val client: Pool) : EventsAppender {
// Execute the prepared query, it is in transaction due to the use of #withTransaction method.
connection.preparedQuery(functionCall)
.execute(params)
}.onComplete { resultQuery ->
if (resultQuery.succeeded()) {
val resultSet = resultQuery.result()
// Extract the result (last_sequence_id) from the first row
val latestSequenceId = resultSet.firstOrNull()?.getLong("last_sequence_id")
if (latestSequenceId != null) {
promise.complete(SequenceNumber(latestSequenceId))
} else {
promise.fail("No last_sequence_id returned from append_events function")
}
}.onSuccess { rowSet ->
// Extract the result (last_sequence_id) from the first row
val latestSequenceId = rowSet.firstOrNull()?.getLong("last_sequence_id")
if (latestSequenceId != null) {
promise.complete(SequenceNumber(latestSequenceId))
} else {
promise.fail(resultQuery.cause())
promise.fail("No last_sequence_id returned from append_events function")
}
}.onFailure {
promise.fail(it)
}

return promise.future()
}

Expand Down

0 comments on commit 3cd56bd

Please sign in to comment.