Skip to content

Commit

Permalink
PR remark
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeda88 committed Dec 22, 2023
1 parent 4fbfc1d commit 5f4cc8d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ class FilterBuilder internal constructor() {
return Filter.Path(this, WhereConstraint.ArrayContainsAny(values))
}

infix fun String.`in`(values: List<Any>): Filter.WithConstraint {
infix fun String.inArray(values: List<Any>): Filter.WithConstraint {
return Filter.Field(this, WhereConstraint.InArray(values))
}

infix fun FieldPath.`in`(values: List<Any>): Filter.WithConstraint {
infix fun FieldPath.inArray(values: List<Any>): Filter.WithConstraint {
return Filter.Path(this, WhereConstraint.InArray(values))
}

infix fun String.notIn(values: List<Any>): Filter.WithConstraint {
infix fun String.notInArray(values: List<Any>): Filter.WithConstraint {
return Filter.Field(this, WhereConstraint.NotInArray(values))
}

infix fun FieldPath.notIn(values: List<Any>): Filter.WithConstraint {
infix fun FieldPath.notInArray(values: List<Any>): Filter.WithConstraint {
return Filter.Path(this, WhereConstraint.NotInArray(values))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fun Query.where(path: FieldPath, lessThan: Any? = null, greaterThan: Any? = null
fun Query.where(field: String, inArray: List<Any>? = null, arrayContainsAny: List<Any>? = null) = where {
all(
*listOfNotNull(
inArray?.let { field `in` it },
inArray?.let { field inArray it },
arrayContainsAny?.let { field containsAny it },
).toTypedArray()
)
Expand All @@ -122,7 +122,7 @@ fun Query.where(field: String, inArray: List<Any>? = null, arrayContainsAny: Lis
fun Query.where(path: FieldPath, inArray: List<Any>? = null, arrayContainsAny: List<Any>? = null) = where {
all(
*listOfNotNull(
inArray?.let { path `in` it },
inArray?.let { path inArray it },
arrayContainsAny?.let { path containsAny it },
).toTypedArray()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import dev.gitlive.firebase.apps
import dev.gitlive.firebase.initialize
import dev.gitlive.firebase.runBlockingTest
import dev.gitlive.firebase.runTest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.withContext
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -702,13 +700,13 @@ class FirebaseFirestoreTest {

val fieldQuery = firestore
.collection("testFirestoreQuerying")
.where { "prop1" `in` listOf("aaa", "bbb") }
.where { "prop1" inArray listOf("aaa", "bbb") }

fieldQuery.assertDocuments(FirestoreTest.serializer(), testOne, testTwo)

val pathQuery = firestore
.collection("testFirestoreQuerying")
.where { FieldPath(FirestoreTest::prop1.name) `in` listOf("ccc", "ddd") }
.where { FieldPath(FirestoreTest::prop1.name) inArray listOf("ccc", "ddd") }

pathQuery.assertDocuments(FirestoreTest.serializer(), testThree)
}
Expand All @@ -719,13 +717,13 @@ class FirebaseFirestoreTest {

val fieldQuery = firestore
.collection("testFirestoreQuerying")
.where { "prop1" notIn listOf("aaa", "bbb") }
.where { "prop1" notInArray listOf("aaa", "bbb") }

fieldQuery.assertDocuments(FirestoreTest.serializer(), testThree)

val pathQuery = firestore
.collection("testFirestoreQuerying")
.where { FieldPath(FirestoreTest::prop1.name) notIn listOf("ccc", "ddd") }
.where { FieldPath(FirestoreTest::prop1.name) notInArray listOf("ccc", "ddd") }

pathQuery.assertDocuments(FirestoreTest.serializer(), testOne, testTwo)
}
Expand All @@ -737,7 +735,7 @@ class FirebaseFirestoreTest {
val andQuery = firestore
.collection("testFirestoreQuerying")
.where {
FieldPath(FirestoreTest::prop1.name) `in` listOf("aaa", "bbb") and (FieldPath(FirestoreTest::count.name) equalTo 1)
FieldPath(FirestoreTest::prop1.name) inArray listOf("aaa", "bbb") and (FieldPath(FirestoreTest::count.name) equalTo 1)
}
andQuery.assertDocuments(FirestoreTest.serializer(), testOne)

Expand Down

0 comments on commit 5f4cc8d

Please sign in to comment.