diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 2469b736..edb1b61b 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1090,6 +1090,77 @@ describe("firestore", () => { limit(25)); // [END paginate] }); + + it("should handle OR queries", async () => { + const { collection, query, where, and } = require("firebase/firestore"); + // [START or_query] + const q = query(collection(db, "cities"), and( + where('state', '==', 'CA'), + or( + where('capital', '==', true), + where('population', '>=', 1000000) + ) + )); + // [END or_query] + }); + + it("should allow for 30 or fewer disjunctions", async () => { + const { collection, query, where, and } = require("firebase/firestore"); + const collectionRef = collection(db, "cities"); + // [START one_disjunction] + query(collectionRef, where("a", "==", 1)); + // [END one_disjunction] + + // [START two_disjunctions] + query(collectionRef, or( where("a", "==", 1), where("b", "==", 2) )); + // [END two_disjunctions] + + // [START four_disjunctions] + query(collectionRef, + or( and( where("a", "==", 1), where("c", "==", 3) ), + and( where("a", "==", 1), where("d", "==", 4) ), + and( where("b", "==", 2), where("c", "==", 3) ), + and( where("b", "==", 2), where("d", "==", 4) ) + ) + ); + // [END four_disjunctions] + + // [START four_disjunctions_compact] + query(collectionRef, + and( or( where("a", "==", 1), where("b", "==", 2) ), + or( where("c", "==", 3), where("d", "==", 4) ) + ) + ); + // [END four_disjunctions_compact] + + expect(() => { + // [START 50_disjunctions] + query(collectionRef, + and( where("a", "in", [1, 2, 3, 4, 5]), + where("b", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + ) + ); + // [END 50_disjunctions] + }).to.throw; + + // [START 20_disjunctions] + query(collectionRef, + or( where("a", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), + where("b", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + ) + ); + // [END 20_disjunctions] + + // [START 10_disjunctions] + query(collectionRef, + and( where("a", "in", [1, 2, 3, 4, 5]), + or( where("b", "==", 2), + where("c", "==", 3) + ) + ) + ); + // [END 10_disjunctions] + }); }); describe('collectionGroup(landmarks)', () => { diff --git a/snippets/firestore-next/test-firestore/four_disjunctions.js b/snippets/firestore-next/test-firestore/four_disjunctions.js new file mode 100644 index 00000000..12ed21ee --- /dev/null +++ b/snippets/firestore-next/test-firestore/four_disjunctions.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START four_disjunctions_modular] +query(collectionRef, + or( and( where("a", "==", 1), where("c", "==", 3) ), + and( where("a", "==", 1), where("d", "==", 4) ), + and( where("b", "==", 2), where("c", "==", 3) ), + and( where("b", "==", 2), where("d", "==", 4) ) + ) +); +// [END four_disjunctions_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/four_disjunctions_compact.js b/snippets/firestore-next/test-firestore/four_disjunctions_compact.js new file mode 100644 index 00000000..7421b01a --- /dev/null +++ b/snippets/firestore-next/test-firestore/four_disjunctions_compact.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START four_disjunctions_compact_modular] +query(collectionRef, + and( or( where("a", "==", 1), where("b", "==", 2) ), + or( where("c", "==", 3), where("d", "==", 4) ) + ) +); +// [END four_disjunctions_compact_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/one_disjunction.js b/snippets/firestore-next/test-firestore/one_disjunction.js new file mode 100644 index 00000000..f2a5ebbe --- /dev/null +++ b/snippets/firestore-next/test-firestore/one_disjunction.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START one_disjunction_modular] +query(collectionRef, where("a", "==", 1)); +// [END one_disjunction_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/or_query.js b/snippets/firestore-next/test-firestore/or_query.js new file mode 100644 index 00000000..f9655e59 --- /dev/null +++ b/snippets/firestore-next/test-firestore/or_query.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START or_query_modular] +const query = query(collection(db, "cities"), and( + where('name', '>', 'L'), + or( + where('capital', '==', true), + where('population', '>=', 1000000) + ) +)); +// [END or_query_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/two_disjunctions.js b/snippets/firestore-next/test-firestore/two_disjunctions.js new file mode 100644 index 00000000..e9015fc3 --- /dev/null +++ b/snippets/firestore-next/test-firestore/two_disjunctions.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START two_disjunctions_modular] +query(collectionRef, or( where("a", "==", 1), where("b", "==", 2) )); +// [END two_disjunctions_modular] \ No newline at end of file