Commit 4ccf07dd authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

fix query right join select

parent 296ca215
...@@ -64,7 +64,6 @@ class AlbumsContractModule @Inject constructor( ...@@ -64,7 +64,6 @@ class AlbumsContractModule @Inject constructor(
private val fetchTopLevelAlbumsDb = private val fetchTopLevelAlbumsDb =
db.getTopLevelAlbums() db.getTopLevelAlbums()
.toObservable()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
private fun fetchTopLevelAlbums(): Observable<List<AlbumPreviewModel>> = private fun fetchTopLevelAlbums(): Observable<List<AlbumPreviewModel>> =
...@@ -99,8 +98,6 @@ class AlbumsContractModule @Inject constructor( ...@@ -99,8 +98,6 @@ class AlbumsContractModule @Inject constructor(
private fun fetchAlbumsDb(parentAlbumId:Int) = private fun fetchAlbumsDb(parentAlbumId:Int) =
db.getChildAlbums(parentAlbumId) db.getChildAlbums(parentAlbumId)
.toList()
.toObservable()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
private fun fetchAlbums(parentId:Int): Observable<List<AlbumPreviewModel>> = private fun fetchAlbums(parentId:Int): Observable<List<AlbumPreviewModel>> =
......
...@@ -18,8 +18,8 @@ interface IDb { ...@@ -18,8 +18,8 @@ interface IDb {
fun <T : List<Persistable>> blockingUpsert(entity: T) fun <T : List<Persistable>> blockingUpsert(entity: T)
fun userObservableResult(uuid: Int): Observable<ReactiveResult<UserEntity>> fun userObservableResult(uuid: Int): Observable<ReactiveResult<UserEntity>>
fun fetchArticles(feedAlias: String, pageSize: Int, startIndex: Int): Observable<ArticleEntity> fun fetchArticles(feedAlias: String, pageSize: Int, startIndex: Int): Observable<ArticleEntity>
fun getTopLevelAlbums(): Single<MutableList<ImageAlbumEntity>> fun getTopLevelAlbums(): Observable<List<ImageAlbumEntity>>
fun getChildAlbums(parentId: Int): Observable<ImageAlbumEntity> fun getChildAlbums(parentId: Int): Observable<List<ImageAlbumEntity>>
fun checkIfExistsAlbumJunction(albumId: Int, parentAlbumId: Int): ImageAlbumJunctionEntity? fun checkIfExistsAlbumJunction(albumId: Int, parentAlbumId: Int): ImageAlbumJunctionEntity?
fun getFeed(feedAlias: String): ReactiveResult<FeedEntity> fun getFeed(feedAlias: String): ReactiveResult<FeedEntity>
fun getArticle(id: Int): ReactiveResult<ArticleEntity> fun getArticle(id: Int): ReactiveResult<ArticleEntity>
......
...@@ -45,52 +45,58 @@ class RequeryRepository @Inject constructor( ...@@ -45,52 +45,58 @@ class RequeryRepository @Inject constructor(
) )
: IDb { : IDb {
private inline fun <reified T:Persistable> fetchAll() = private inline fun <reified T : Persistable> fetchAll() =
store.select(T::class) store.select(T::class)
override fun upsertUser(entity:UserEntity): Observable<UserEntity> = override fun upsertUser(entity: UserEntity): Observable<UserEntity> =
store.upsert(entity).toObservable() store.upsert(entity).toObservable()
override fun <T:Persistable> upsert(entity:T) = store.upsert(entity) override fun <T : Persistable> upsert(entity: T) = store.upsert(entity)
override fun <T : List<Persistable>> upsert(entity: T): Single<Iterable<Persistable>> = override fun <T : List<Persistable>> upsert(entity: T): Single<Iterable<Persistable>> =
store.upsert(entity) store.upsert(entity)
override fun <T:List<Persistable>> blockingUpsert(entity:T) = override fun <T : List<Persistable>> blockingUpsert(entity: T) =
store.upsert(entity).toObservable().blockingSubscribe() store.upsert(entity).toObservable().blockingSubscribe()
override fun fetchFeeds(): Observable<FeedEntity> = override fun fetchFeeds(): Observable<FeedEntity> =
fetchAll<FeedEntity>().get().observable() fetchAll<FeedEntity>().get().observable()
override fun getFeed(feedAlias:String): ReactiveResult<FeedEntity> = override fun getFeed(feedAlias: String): ReactiveResult<FeedEntity> =
fetchAll<FeedEntity>().where(FeedEntity.ALIAS.eq(feedAlias)) fetchAll<FeedEntity>().where(FeedEntity.ALIAS.eq(feedAlias))
.get() .get()
override fun getArticle(id:Int): ReactiveResult<ArticleEntity> = override fun getArticle(id: Int): ReactiveResult<ArticleEntity> =
fetchAll<ArticleEntity>().where(ArticleEntity.ID.eq(id)) fetchAll<ArticleEntity>().where(ArticleEntity.ID.eq(id))
.get() .get()
override fun getTopLevelAlbums(): Single<MutableList<ImageAlbumEntity>> = override fun getTopLevelAlbums(): Observable<List<ImageAlbumEntity>> =
fetchAll<ImageAlbumEntity>() Observable.fromArray(
.join(ImageAlbumJunctionEntity::class) store.raw(
.on(ImageAlbumJunctionEntity.ALBUM_ID.eq(ImageAlbumEntity.ID)) ImageAlbumEntity::class,
.where(ImageAlbumJunctionEntity.ALBUM_ID.isNull()) "SELECT alb.* from ImageAlbumJunction albJun " +
.get().observable().toList() "left join ImageAlbum alb on albJun.albumId = alb.id " +
"WHERE albJun.albumId is null "
override fun getChildAlbums(parentId:Int): Observable<ImageAlbumEntity> = ).toList()
store.select(ImageAlbumEntity::class) )
.join(ImageAlbumJunctionEntity::class)
.on(ImageAlbumJunctionEntity.ALBUM_ID.eq(ImageAlbumEntity.ID)) override fun getChildAlbums(parentId: Int): Observable<List<ImageAlbumEntity>> =
.where(ImageAlbumJunctionEntity.PARENT_ID.eq(parentId)) Observable.fromArray(
.get().observable() store.raw(
ImageAlbumEntity::class,
"SELECT alb.* from ImageAlbumJunction albJun " +
"left join ImageAlbum alb on albJun.albumId = alb.id " +
"WHERE albJun.albumId is $parentId "
).toList()
)
override fun getPhotos(albumId: Int): Observable<GalleryPhotoEntity> = override fun getPhotos(albumId: Int): Observable<GalleryPhotoEntity> =
store.select(GalleryPhotoEntity::class) store.select(GalleryPhotoEntity::class)
.where(GalleryPhotoEntity.ALBUM_ID.eq(albumId)) .where(GalleryPhotoEntity.ALBUM_ID.eq(albumId))
.get().observable() .get().observable()
override fun fetchArticles(feedAlias:String,pageSize:Int,startIndex:Int) override fun fetchArticles(feedAlias: String, pageSize: Int, startIndex: Int)
: Observable<ArticleEntity> = : Observable<ArticleEntity> =
fetchAll<ArticleEntity>() fetchAll<ArticleEntity>()
.where(ArticleEntity.FEED_ID.eq(feedAlias)) .where(ArticleEntity.FEED_ID.eq(feedAlias))
...@@ -99,25 +105,23 @@ class RequeryRepository @Inject constructor( ...@@ -99,25 +105,23 @@ class RequeryRepository @Inject constructor(
.offset(startIndex) .offset(startIndex)
.get().observable() .get().observable()
override fun checkIfExistsAlbumJunction(albumId:Int,parentAlbumId:Int) = override fun checkIfExistsAlbumJunction(albumId: Int, parentAlbumId: Int) =
fetchAll<ImageAlbumJunctionEntity>() fetchAll<ImageAlbumJunctionEntity>()
.where(ImageAlbumJunctionEntity.ALBUM_ID.eq(albumId)) .where(ImageAlbumJunctionEntity.ALBUM_ID.eq(albumId))
.and(ImageAlbumJunctionEntity.PARENT_ID.eq(parentAlbumId)) .and(ImageAlbumJunctionEntity.PARENT_ID.eq(parentAlbumId))
.get() .get()
.firstOrNull() .firstOrNull()
override fun fetchUser(uuid:Int): Observable<UserEntity> = override fun fetchUser(uuid: Int): Observable<UserEntity> =
fetchAll<UserEntity>().where(UserEntity.UUID.eq(uuid)).get().observable() fetchAll<UserEntity>().where(UserEntity.UUID.eq(uuid)).get().observable()
fun upsertFeeds(entity:List<FeedEntity>) = fun upsertFeeds(entity: List<FeedEntity>) =
store.upsert(entity) store.upsert(entity)
override fun userObservableResult(uuid:Int) = override fun userObservableResult(uuid: Int) =
store.select(UserEntity::class) store.select(UserEntity::class)
.where(UserEntity.UUID.eq(uuid)) .where(UserEntity.UUID.eq(uuid))
.get() .get()
.observableResult() .observableResult()
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment