Comments (4)
To support also insert operations:
fun <T: Any> SelectOperation.toPipeline(mapper: (ResultSet) -> T) = Pipeline(this, mapper = mapper)
fun <T: Any> InsertOperation.toPipeline(mapper: (ResultSet) -> T) = Pipeline(insertOperation = this, mapper = mapper)
class Pipeline<T: Any>(val selectOperation: SelectOperation? = null,
val insertOperation: InsertOperation? = null,
val mapper: (ResultSet) -> T
) {
fun toObservable(): Observable<T> = selectOperation?.toObservable(mapper) ?: insertOperation?.toObservable(mapper) ?: throw Exception("Operation must be provided")
fun toFlowable(): Flowable<T> = selectOperation?.toFlowable(mapper) ?: insertOperation?.toFlowable(mapper) ?: throw Exception("Operation must be provided")
fun toSingle(): Single<T> = selectOperation?.toSingle(mapper) ?: insertOperation?.toSingle(mapper) ?: throw Exception("Operation must be provided")
fun toMaybe(): Maybe<T> = selectOperation?.toMaybe(mapper) ?: insertOperation?.toMaybe(mapper) ?: throw Exception("Operation must be provided")
fun toSequence(): ResultSetSequence<T> = selectOperation?.toSequence(mapper) ?: insertOperation?.toSequence(mapper) ?: throw Exception("Operation must be provided")
fun blockingFirst() = selectOperation?.blockingFirst(mapper) ?: insertOperation?.blockingFirst(mapper) ?: throw Exception("Operation must be provided")
fun blockingFirstOrNull() = selectOperation?.blockingFirstOrNull(mapper) ?: insertOperation?.blockingFirstOrNull(mapper) ?: throw Exception("Operation must be provided")
}
from rxkotlin-jdbc.
I thought this was achieved by Publisher<T>
? What advantage does Pipeline
bring over Publisher<T>
?
from rxkotlin-jdbc.
@ZakTaccardi I'm not really trying to create an interface or contract. What I'm trying to achieve is if I have a JBDC query, I want the option for the API user to stream the results with the fluent pipeline they want, while having all of them share the same defined mapping operation (ResultSet) -> T
.
This way, client can call MyItem.all.toObservable()
rather than MyItem.all.toObservable(::MyItem)
, where ::MyItem
maps each ResultSet
to a MyItem
.
from rxkotlin-jdbc.
Sometimes, as a user of an API, I want to return items as a Sequence
, other times a Stream
, and other times an Observable
or Flowable
.
from rxkotlin-jdbc.
Related Issues (11)
- Release 0.1 version on Maven
- Unexpected behavior of InsertOperation.parameters HOT 6
- Connection leak on execute (Hikari) HOT 7
- rxkotlin 3 and Kotlin 4.1.10
- Support named parameters
- Issues with nameless parameters HOT 3
- Add asList() and asMap() operators HOT 1
- Support Date and Timestamp in parameter processing
- Allow reuse of SelectOperation, InsertOperation, UpdateOperation
- Implement batching
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxkotlin-jdbc.