Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to fetch a single entity with sql conditions #113

Merged
merged 2 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ public interface EntityDao<Id, E, Condition> {
@NonNull
Maybe<E> getEntity(@NonNull Id id);

/**
* Retrieves the entity that satisfies the conditions, if any
* If more than one entity satisfy the conditions, the first one will be returned
*
* @param conditions to find the entity
* @return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the entity, if exists

*/
@CheckResult
@NonNull
Maybe<E> getEntity(@NonNull Condition... conditions);

/**
* Creates the {@code entity} and returns it.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ public Maybe<D> getEntity(@NonNull Id id) {
.subscribeOn(Schedulers.io());
}

@CheckResult
@NonNull
@Override
public Maybe<D> getEntity(@NonNull SQLOperator... conditions) {
return Maybe
.fromCallable(() -> new Select()
.from(getModelClass())
.where(conditions)
.querySingle())
.subscribeOn(Schedulers.io());
}

@CheckResult
@NonNull
@Override
Expand Down