Skip to content

Commit

Permalink
OR Query (#783)
Browse files Browse the repository at this point in the history
* Initial implementation of OR Query

* Add documentation

* Add documentation

* Add tests

* REview feedback changes

* Initial implementation of OR Query

* Add documentation

* Add documentation

* Add tests

* REview feedback changes

* Separate out AND/OR Query tests that require composite index. Only run these tests against emulator, that does not require index.

* Separate out AND/OR Query tests that require composite index. Only run these tests against emulator, that does not require index.
  • Loading branch information
tom-andersen authored Sep 27, 2023
1 parent fa6251a commit a986e4d
Show file tree
Hide file tree
Showing 7 changed files with 661 additions and 0 deletions.
1 change: 1 addition & 0 deletions firestore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(firebase_firestore_src_documented
src/DocumentSnapshot.cs
src/FieldPath.cs
src/FieldValue.cs
src/Filter.cs
src/FirebaseFirestore.cs
src/FirebaseFirestoreSettings.cs
src/FirestoreDataAttribute.cs
Expand Down
325 changes: 325 additions & 0 deletions firestore/src/Filter.cs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions firestore/src/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public AggregateQuery Count {
}
}

/// <summary>
/// Creates and returns a new Query with the additional filter.
/// </summary>
/// <param name="filter">The new filter to apply to the existing query.</param>
/// <returns>
/// The created Query.
/// </returns>
public Query Where(Filter filter) {
Preconditions.CheckNotNull(filter, nameof(filter));
return new Query(_proxy.Where(filter.Proxy), Firestore);
}

/// <summary>
/// Creates and returns a new <c>Query</c> with the additional filter that documents must
Expand Down
13 changes: 13 additions & 0 deletions firestore/src/swig/firestore.i
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,20 @@ SWIG_CREATE_PROXY(firebase::firestore::WriteBatch);
SWIG_CREATE_PROXY(firebase::firestore::MetadataChanges)
%include "firestore/src/include/firebase/firestore/metadata_changes.h"
// Generate a C# wrapper for Filter. Must be above Query.
SWIG_CREATE_PROXY(firebase::firestore::Filter);
%rename("%s") firebase::firestore::Filter::ArrayContains;
%rename("%s") firebase::firestore::Filter::EqualTo;
%rename("%s") firebase::firestore::Filter::NotEqualTo;
%rename("%s") firebase::firestore::Filter::GreaterThan;
%rename("%s") firebase::firestore::Filter::GreaterThanOrEqualTo;
%rename("%s") firebase::firestore::Filter::LessThan;
%rename("%s") firebase::firestore::Filter::LessThanOrEqualTo;
%include "firestore/src/include/firebase/firestore/filter.h"
// Generate a C# wrapper for Query and Query::Direction. Must be above CollectionReference.
SWIG_CREATE_PROXY(firebase::firestore::Query);
%rename("%s") firebase::firestore::Query::Where;
%rename("%s") firebase::firestore::Query::WhereEqualTo;
%rename("%s") firebase::firestore::Query::WhereNotEqualTo;
%rename("%s") firebase::firestore::Query::WhereLessThan;
Expand Down Expand Up @@ -541,6 +553,7 @@ namespace firestore {
%template(DocumentSnapshotVector) csharp::Vector<DocumentSnapshot>;
%template(FieldPathVector) csharp::Vector<FieldPath>;
%template(FieldValueVector) csharp::Vector<FieldValue>;
%template(FilterVector) csharp::Vector<Filter>;
} // namespace firestore
} // namespace firebase
Expand Down
25 changes: 25 additions & 0 deletions firestore/src/swig/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "firestore/src/include/firebase/firestore/document_snapshot.h"
#include "firestore/src/include/firebase/firestore/field_path.h"
#include "firestore/src/include/firebase/firestore/field_value.h"
#include "firestore/src/include/firebase/firestore/filter.h"
#include "firestore/src/include/firebase/firestore/query.h"
#include "firestore/src/include/firebase/firestore/set_options.h"
#include "firestore/src/include/firebase/firestore/write_batch.h"
Expand Down Expand Up @@ -176,6 +177,30 @@ inline Future<void> DocumentReferenceUpdate(
return doc.Update(wrapper.Unwrap());
}

inline Filter FilterArrayContainsAny(const std::string& field, const FieldValue& values) {
return Filter::ArrayContainsAny(field, values.array_value());
}

inline Filter FilterArrayContainsAny(const FieldPath& field, const FieldValue& values) {
return Filter::ArrayContainsAny(field, values.array_value());
}

inline Filter FilterIn(const std::string& field, const FieldValue& values) {
return Filter::In(field, values.array_value());
}

inline Filter FilterIn(const FieldPath& field, const FieldValue& values) {
return Filter::In(field, values.array_value());
}

inline Filter FilterNotIn(const std::string& field, const FieldValue& values) {
return Filter::NotIn(field, values.array_value());
}

inline Filter FilterNotIn(const FieldPath& field, const FieldValue& values) {
return Filter::NotIn(field, values.array_value());
}

inline Query QueryWhereArrayContainsAny(Query& query,
const std::string& field,
const FieldValue& values) {
Expand Down
8 changes: 8 additions & 0 deletions firestore/src/swig/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ inline FieldValue FieldValueArrayRemove(const Vector<FieldValue>& wrapper) {
return FieldValue::ArrayRemove(wrapper.Unwrap());
}

inline Filter FilterAnd(const Vector<Filter>& filters) {
return Filter::And(filters.Unwrap());
}

inline Filter FilterOr(const Vector<Filter>& filters) {
return Filter::Or(filters.Unwrap());
}

inline Vector<DocumentSnapshot> QuerySnapshotDocuments(
const QuerySnapshot& snapshot) {
return Vector<DocumentSnapshot>::Wrap(snapshot.documents());
Expand Down
Loading

0 comments on commit a986e4d

Please sign in to comment.