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(
private val fetchTopLevelAlbumsDb =
db.getTopLevelAlbums()
.toObservable()
.subscribeOn(Schedulers.io())
private fun fetchTopLevelAlbums(): Observable<List<AlbumPreviewModel>> =
......@@ -99,8 +98,6 @@ class AlbumsContractModule @Inject constructor(
private fun fetchAlbumsDb(parentAlbumId:Int) =
db.getChildAlbums(parentAlbumId)
.toList()
.toObservable()
.subscribeOn(Schedulers.io())
private fun fetchAlbums(parentId:Int): Observable<List<AlbumPreviewModel>> =
......
......@@ -18,8 +18,8 @@ interface IDb {
fun <T : List<Persistable>> blockingUpsert(entity: T)
fun userObservableResult(uuid: Int): Observable<ReactiveResult<UserEntity>>
fun fetchArticles(feedAlias: String, pageSize: Int, startIndex: Int): Observable<ArticleEntity>
fun getTopLevelAlbums(): Single<MutableList<ImageAlbumEntity>>
fun getChildAlbums(parentId: Int): Observable<ImageAlbumEntity>
fun getTopLevelAlbums(): Observable<List<ImageAlbumEntity>>
fun getChildAlbums(parentId: Int): Observable<List<ImageAlbumEntity>>
fun checkIfExistsAlbumJunction(albumId: Int, parentAlbumId: Int): ImageAlbumJunctionEntity?
fun getFeed(feedAlias: String): ReactiveResult<FeedEntity>
fun getArticle(id: Int): ReactiveResult<ArticleEntity>
......
......@@ -45,52 +45,58 @@ class RequeryRepository @Inject constructor(
)
: IDb {
private inline fun <reified T:Persistable> fetchAll() =
private inline fun <reified T : Persistable> fetchAll() =
store.select(T::class)
override fun upsertUser(entity:UserEntity): Observable<UserEntity> =
override fun upsertUser(entity: UserEntity): Observable<UserEntity> =
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>> =
store.upsert(entity)
override fun <T:List<Persistable>> blockingUpsert(entity:T) =
override fun <T : List<Persistable>> blockingUpsert(entity: T) =
store.upsert(entity).toObservable().blockingSubscribe()
override fun fetchFeeds(): Observable<FeedEntity> =
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))
.get()
override fun getArticle(id:Int): ReactiveResult<ArticleEntity> =
override fun getArticle(id: Int): ReactiveResult<ArticleEntity> =
fetchAll<ArticleEntity>().where(ArticleEntity.ID.eq(id))
.get()
override fun getTopLevelAlbums(): Single<MutableList<ImageAlbumEntity>> =
fetchAll<ImageAlbumEntity>()
.join(ImageAlbumJunctionEntity::class)
.on(ImageAlbumJunctionEntity.ALBUM_ID.eq(ImageAlbumEntity.ID))
.where(ImageAlbumJunctionEntity.ALBUM_ID.isNull())
.get().observable().toList()
override fun getChildAlbums(parentId:Int): Observable<ImageAlbumEntity> =
store.select(ImageAlbumEntity::class)
.join(ImageAlbumJunctionEntity::class)
.on(ImageAlbumJunctionEntity.ALBUM_ID.eq(ImageAlbumEntity.ID))
.where(ImageAlbumJunctionEntity.PARENT_ID.eq(parentId))
.get().observable()
override fun getTopLevelAlbums(): Observable<List<ImageAlbumEntity>> =
Observable.fromArray(
store.raw(
ImageAlbumEntity::class,
"SELECT alb.* from ImageAlbumJunction albJun " +
"left join ImageAlbum alb on albJun.albumId = alb.id " +
"WHERE albJun.albumId is null "
).toList()
)
override fun getChildAlbums(parentId: Int): Observable<List<ImageAlbumEntity>> =
Observable.fromArray(
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> =
store.select(GalleryPhotoEntity::class)
.where(GalleryPhotoEntity.ALBUM_ID.eq(albumId))
.get().observable()
override fun fetchArticles(feedAlias:String,pageSize:Int,startIndex:Int)
override fun fetchArticles(feedAlias: String, pageSize: Int, startIndex: Int)
: Observable<ArticleEntity> =
fetchAll<ArticleEntity>()
.where(ArticleEntity.FEED_ID.eq(feedAlias))
......@@ -99,25 +105,23 @@ class RequeryRepository @Inject constructor(
.offset(startIndex)
.get().observable()
override fun checkIfExistsAlbumJunction(albumId:Int,parentAlbumId:Int) =
override fun checkIfExistsAlbumJunction(albumId: Int, parentAlbumId: Int) =
fetchAll<ImageAlbumJunctionEntity>()
.where(ImageAlbumJunctionEntity.ALBUM_ID.eq(albumId))
.and(ImageAlbumJunctionEntity.PARENT_ID.eq(parentAlbumId))
.get()
.firstOrNull()
override fun fetchUser(uuid:Int): Observable<UserEntity> =
override fun fetchUser(uuid: Int): Observable<UserEntity> =
fetchAll<UserEntity>().where(UserEntity.UUID.eq(uuid)).get().observable()
fun upsertFeeds(entity:List<FeedEntity>) =
fun upsertFeeds(entity: List<FeedEntity>) =
store.upsert(entity)
override fun userObservableResult(uuid:Int) =
override fun userObservableResult(uuid: Int) =
store.select(UserEntity::class)
.where(UserEntity.UUID.eq(uuid))
.get()
.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