Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created July 9, 2018 15:39
Show Gist options
  • Save olegchir/6cc174e14bb6a58cff713021d044ce06 to your computer and use it in GitHub Desktop.
Save olegchir/6cc174e14bb6a58cff713021d044ce06 to your computer and use it in GitHub Desktop.
SQLClientHelper.inTransactionSingle(client, sqlConnection -> {
return sqlConnection.rxExecute("INSERT INTO albums (name) VALUES ('The Israelites')")
.andThen(sqlConnection.rxExecute("INSERT INTO tracks (album, name) VALUES ('The Israelites', 'Israelites')"))
.andThen(sqlConnection.rxExecute("INSERT INTO tracks (album, name) VALUES ('The Israelites', 'Too Much Too Soon')"))
.andThen(sqlConnection.rxQuery("SELECT name FROM tracks WHERE album = 'The Israelites'").map(ResultSet::getResults))
}).map(rows -> {
// Transform DB rows into a client-friendly JSON object
}).subscribe(json -> {
// Send JSON to the client
}, t -> {
// Send error to the client
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment