public final class QueryObservable
extends <any>
Observable
of SqlBrite.Query
which offers query-specific convenience operators.Constructor and Description |
---|
QueryObservable(<any> upstream) |
Modifier and Type | Method and Description |
---|---|
<T> <any> |
mapToList(<any> mapper)
Given a function mapping the current row of a
Cursor to T , transform each
emitted SqlBrite.Query to a List<T> . |
<T> <any> |
mapToOne(<any> mapper)
Given a function mapping the current row of a
Cursor to T , transform each
emitted SqlBrite.Query which returns a single row to T . |
<T> <any> |
mapToOneOrDefault(<any> mapper,
T defaultValue)
Given a function mapping the current row of a
Cursor to T , transform each
emitted SqlBrite.Query which returns a single row to T . |
<T> <any> |
mapToOptional(<any> mapper)
Given a function mapping the current row of a
Cursor to T , transform each
emitted SqlBrite.Query which returns a single row to Optional<T> . |
protected void |
subscribeActual(<any> observer) |
protected void subscribeActual(<any> observer)
public final <T> <any> mapToOne(<any> mapper)
Cursor
to T
, transform each
emitted SqlBrite.Query
which returns a single row to T
.
It is an error for a query to pass through this operator with more than 1 row in its result
set. Use LIMIT 1
on the underlying SQL query to prevent this. Result sets with 0 rows
do not emit an item.
This method is equivalent to:
flatMap(q -> q.asRows(mapper).take(1))
and a convenience operator for:
lift(Query.mapToOne(mapper))
mapper
- Maps the current Cursor
row to T
. May not return null.public final <T> <any> mapToOneOrDefault(<any> mapper, T defaultValue)
Cursor
to T
, transform each
emitted SqlBrite.Query
which returns a single row to T
.
It is an error for a query to pass through this operator with more than 1 row in its result
set. Use LIMIT 1
on the underlying SQL query to prevent this. Result sets with 0 rows
emit defaultValue
.
This method is equivalent to:
flatMap(q -> q.asRows(mapper).take(1).defaultIfEmpty(defaultValue))
and a convenience operator for:
lift(Query.mapToOneOrDefault(mapper, defaultValue))
mapper
- Maps the current Cursor
row to T
. May not return null.defaultValue
- Value returned if result set is emptypublic final <T> <any> mapToOptional(<any> mapper)
Cursor
to T
, transform each
emitted SqlBrite.Query
which returns a single row to Optional<T>
.
It is an error for a query to pass through this operator with more than 1 row in its result
set. Use LIMIT 1
on the underlying SQL query to prevent this. Result sets with 0 rows
emit Optional.empty()
This method is equivalent to:
flatMap(q -> q.asRows(mapper).take(1).map(Optional::of).defaultIfEmpty(Optional.empty())
and a convenience operator for:
lift(Query.mapToOptional(mapper))
mapper
- Maps the current Cursor
row to T
. May not return null.public final <T> <any> mapToList(<any> mapper)
Cursor
to T
, transform each
emitted SqlBrite.Query
to a List<T>
.
Be careful using this operator as it will always consume the entire cursor and create objects for each row, every time this observable emits a new query. On tables whose queries update frequently or very large result sets this can result in the creation of many objects.
This method is equivalent to:
flatMap(q -> q.asRows(mapper).toList())
and a convenience operator for:
lift(Query.mapToList(mapper))
Consider using SqlBrite.Query.asRows(<any>)
if you need to limit or filter in memory.
mapper
- Maps the current Cursor
row to T
. May not return null.