select Async
fun selectAsync(builder: QueryBuilder.() -> Unit, onComplete: (List<Map<String, Any?>>) -> Unit, onError: (Throwable) -> Unit = { it.printStackTrace() })
Performs an asynchronous SELECT query on this table.
This method allows you to define a normal query using the same builder pattern as select
, but the query is executed in a background thread using CompletableFuture. Once the query finishes, the result is returned to the onComplete
callback on the main thread. If an exception occurs during the query, the onError
callback will be triggered.
Parameters
builder
A lambda to define the query conditions, similar to select
.
Example:
table.selectAsync(
{
columns("*")
where("uuid = '${player.uniqueId}'")
},
onComplete = { results ->
if (results.isNotEmpty()) {
val count = results.first()["count"] as? Int ?: 0
player.sendMessage("You own $count spawners.")
} else {
player.sendMessage("You have no spawners registered.")
}
},
onError = { error ->
player.sendMessage("An error occurred while fetching your spawner data.")
error.printStackTrace()
}
)
Content copied to clipboard
on Complete
The function to run when the query successfully completes. The result is passed as a list of rows.
on Error
The function to run if the query fails. Receives the thrown exception as parameter. (Optional, default prints stack trace).