Skip to content

Commit

Permalink
Merge pull request #50 from SchwarzIT/feature/limit_query_results
Browse files Browse the repository at this point in the history
Feature/limit query results
  • Loading branch information
tobias-brodmann-ergon authored Nov 19, 2021
2 parents be2c040 + 3227c0b commit d2bf279
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object PersistenceConfig {
val typeConversions: Map<KClass<*>, TypeConversion>
fun getDocument(id: String, dbName: String): Map<String, Any>?
fun getDocuments(ids: List<String>, dbName: String): List<Map<String, Any>?>
fun queryDoc(dbName: String, queryParams: Map<String, Any>): List<Map<String, Any>>
fun queryDoc(dbName: String, queryParams: Map<String, Any>, limit: Int? = null): List<Map<String, Any>>

@Throws(PersistenceException::class)
fun deleteDocument(id: String, dbName: String)
Expand All @@ -27,7 +27,7 @@ object PersistenceConfig {

suspend fun getDocuments(ids: List<String>, dbName: String): List<Map<String, Any>>

suspend fun queryDoc(dbName: String, queryParams: Map<String, Any>): List<Map<String, Any>>
suspend fun queryDoc(dbName: String, queryParams: Map<String, Any>, limit: Int? = null): List<Map<String, Any>>

@Throws(PersistenceException::class)
suspend fun deleteDocument(id: String, dbName: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ abstract class Couchbase2Connector : PersistenceConfig.Connector {
}

@Throws(PersistenceException::class)
override fun queryDoc(dbName: String, queryParams: Map<String, Any>): List<Map<String, Any>> {
override fun queryDoc(dbName: String, queryParams: Map<String, Any>, limit: Int?): List<Map<String, Any>> {
try {

val builder = QueryBuilder.select(SelectResult.expression(Meta.id), SelectResult.all())
Expand All @@ -98,6 +98,8 @@ abstract class Couchbase2Connector : PersistenceConfig.Connector {
builder.where(it)
}

limit?.let { builder.limit(Expression.intValue(limit)) }

return queryResultToMap(builder.execute())
} catch (e: CouchbaseLiteException) {
throw PersistenceException(e)
Expand Down
4 changes: 2 additions & 2 deletions demo/src/test/java/kaufland/com/demo/TypeConversionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class TypeConversionTest {
TODO("Not yet implemented")
}

override fun queryDoc(dbName: String, queryParams: Map<String, Any>): List<Map<String, Any>> {
override fun queryDoc(dbName: String, queryParams: Map<String, Any>, limit: Int?): List<Map<String, Any>> {
throw Exception("should not called")
}

override fun deleteDocument(id: String, dbName: String) {
throw Exception("should not called")
}

override fun upsertDocument(document: MutableMap<String, Any>, id: String?, dbName: String) {
override fun upsertDocument(document: MutableMap<String, Any>, id: String?, dbName: String): Map<String, Any> {
throw Exception("should not called")
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class ProductWrapperTest {
TODO("Not yet implemented")
}

override fun queryDoc(dbName: String, queryParams: Map<String, Any>): List<Map<String, Any>> {
override fun queryDoc(dbName: String, queryParams: Map<String, Any>, limit: Int?): List<Map<String, Any>> {
TODO("Not yet implemented")
}

override fun deleteDocument(id: String, dbName: String) {
TODO("Not yet implemented")
}

override fun upsertDocument(document: MutableMap<String, Any>, id: String?, dbName: String) {
override fun upsertDocument(document: MutableMap<String, Any>, id: String?, dbName: String): Map<String, Any> {
TODO("Not yet implemented")
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class DummyMapperSourceTest {
TODO("Not yet implemented")
}

override fun queryDoc(dbName: String, queryParams: Map<String, Any>): List<Map<String, Any>> {
override fun queryDoc(dbName: String, queryParams: Map<String, Any>, limit: Int?): List<Map<String, Any>> {
return emptyList()
}

override fun deleteDocument(id: String, dbName: String) {
// nope
}

override fun upsertDocument(document: MutableMap<String, Any>, id: String?, dbName: String) {
// nope
override fun upsertDocument(document: MutableMap<String, Any>, id: String?, dbName: String): Map<String, Any> {
TODO("Not yet implemented")
}
})
}
Expand Down Expand Up @@ -68,7 +68,8 @@ class DummyMapperSourceTest {
assertEquals("oldValue", newObj.innerObject.myString)
assertEquals("oldValue", newObj.innerObjectList[0].myString)
assertEquals("oldValue", newObj.innerObjectMap["test"]!!.myString)
assertEquals("myLiveVal", newObj.liveData.exposedVal)
assertEquals("myLiveVal", newObj.liveData.exposedVal!!.test1)
assertEquals(1, newObj.liveData.exposedVal!!.test2)
assertEquals(2, newObj.nullableList.size)
assertEquals(null, newObj.nullableList[0])
}
Expand Down

0 comments on commit d2bf279

Please sign in to comment.