Skip to content

Commit

Permalink
Initialization fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeda88 committed Dec 20, 2023
1 parent b8be819 commit 50b3b61
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ actual open class Query(open val android: AndroidQuery) {
awaitClose { listener.remove() }
}

internal actual fun where(field: String, vararg clauses: WhereClause) = Query(
actual fun where(field: String, vararg clauses: WhereClause) = Query(
clauses.fold(android) { query, clause ->
when (clause) {
is WhereClause.ForNullableObject -> {
Expand Down Expand Up @@ -340,7 +340,7 @@ actual open class Query(open val android: AndroidQuery) {
}
)

internal actual fun where(path: FieldPath, vararg clauses: WhereClause) = Query(
actual fun where(path: FieldPath, vararg clauses: WhereClause) = Query(
clauses.fold(android) { query, clause ->
when (clause) {
is WhereClause.ForNullableObject -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ expect open class Query {
fun snapshots(includeMetadataChanges: Boolean = false): Flow<QuerySnapshot>
suspend fun get(): QuerySnapshot

internal fun where(field: String, vararg clauses: WhereClause): Query
internal fun where(path: FieldPath, vararg clauses: WhereClause): Query
fun where(field: String, vararg clauses: WhereClause): Query
fun where(path: FieldPath, vararg clauses: WhereClause): Query

internal fun _orderBy(field: String, direction: Direction): Query
internal fun _orderBy(field: FieldPath, direction: Direction): Query
Expand All @@ -113,10 +113,12 @@ private val Any.safeValue: Any get() = when (this) {
else -> this
}

fun Query.where(field: String, equalTo: Any?) = where(field, WhereClause.EqualTo(equalTo))
fun Query.where(path: FieldPath, equalTo: Any?) = where(path, WhereClause.EqualTo(equalTo))
fun Query.whereNot(field: String, notEqualTo: Any?) = where(field, WhereClause.NotEqualTo(notEqualTo))
fun Query.whereNot(path: FieldPath, notEqualTo: Any?) = where(path, WhereClause.NotEqualTo(notEqualTo))
fun Query.where(field: String, equalTo: Any?) = where(field, clause = WhereClause.EqualTo(equalTo))
fun Query.where(path: FieldPath, equalTo: Any?) = where(path, clause = WhereClause.EqualTo(equalTo))
fun Query.where(field: String, clause: WhereClause): Query = where(field, clauses = listOf(clause).toTypedArray())
fun Query.where(path: FieldPath, clause: WhereClause): Query = where(path, clauses = listOf(clause).toTypedArray())
fun Query.whereNot(field: String, notEqualTo: Any?) = where(field, clause = WhereClause.NotEqualTo(notEqualTo))
fun Query.whereNot(path: FieldPath, notEqualTo: Any?) = where(path, clause = WhereClause.NotEqualTo(notEqualTo))
fun Query.where(field: String,
lessThan: Any? = null,
greaterThan: Any? = null,
Expand All @@ -129,7 +131,7 @@ fun Query.where(field: String,
) =
where(
field,
listOfNotNull(
clauses = listOfNotNull(
lessThan?.let { WhereClause.LessThan(it) },
greaterThan?.let { WhereClause.GreaterThan(it) },
lessThanOrEqualTo?.let { WhereClause.LessThanOrEqualTo(it) },
Expand All @@ -138,7 +140,7 @@ fun Query.where(field: String,
arrayContainsAny?.let { WhereClause.ArrayContainsAny(it) },
inArray?.let { WhereClause.InArray(it) },
notInArray?.let { WhereClause.NotInArray(it) }
)
).toTypedArray()
)

fun Query.where(path: FieldPath,
Expand All @@ -153,7 +155,7 @@ fun Query.where(path: FieldPath,
) =
where(
path,
listOfNotNull(
clauses = listOfNotNull(
lessThan?.let { WhereClause.LessThan(it) },
greaterThan?.let { WhereClause.GreaterThan(it) },
lessThanOrEqualTo?.let { WhereClause.LessThanOrEqualTo(it) },
Expand All @@ -162,10 +164,9 @@ fun Query.where(path: FieldPath,
arrayContainsAny?.let { WhereClause.ArrayContainsAny(it) },
inArray?.let { WhereClause.InArray(it) },
notInArray?.let { WhereClause.NotInArray(it) }
)
).toTypedArray()
)


fun Query.orderBy(field: String, direction: Direction = Direction.ASCENDING) = _orderBy(field, direction)
fun Query.orderBy(field: FieldPath, direction: Direction = Direction.ASCENDING) = _orderBy(field, direction)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ actual open class Query(open val ios: FIRQuery) {
awaitClose { listener.remove() }
}

internal actual fun where(field: String, vararg clauses: WhereClause) = Query(
actual fun where(field: String, vararg clauses: WhereClause) = Query(
clauses.fold(ios) { query, clause ->
when (clause) {
is WhereClause.EqualTo -> query.queryWhereField(field, isEqualTo = clause.safeValue ?: NSNull)
Expand All @@ -289,7 +289,7 @@ actual open class Query(open val ios: FIRQuery) {
}
)

internal actual fun where(path: FieldPath, vararg clauses: WhereClause) = Query(
actual fun where(path: FieldPath, vararg clauses: WhereClause) = Query(
clauses.fold(ios) { query, clause ->
when (clause) {
is WhereClause.EqualTo -> query.queryWhereFieldPath(path.ios, isEqualTo = clause.safeValue ?: NSNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ actual open class Query(open val js: JsQuery) {

actual fun limit(limit: Number) = Query(query(js, jsLimit(limit)))

internal actual fun where(field: String, vararg clauses: WhereClause) = Query(
actual fun where(field: String, vararg clauses: WhereClause) = Query(
clauses.fold(js) { query, clause ->
val value = when (clause) {
is WhereClause.ForNullableObject -> clause.safeValue
Expand All @@ -303,7 +303,7 @@ actual open class Query(open val js: JsQuery) {
query(query, jsWhere(field, clause.filterOp, value))
}
)
internal actual fun where(path: FieldPath, vararg clauses: WhereClause) = Query(
actual fun where(path: FieldPath, vararg clauses: WhereClause) = Query(
clauses.fold(js) { query, clause ->
val value = when (clause) {
is WhereClause.ForNullableObject -> clause.safeValue
Expand Down

0 comments on commit 50b3b61

Please sign in to comment.