elersong / fireorm24

ORM for Firebase Firestore 🔥 updated for 2024
MIT License
1 stars 0 forks source link

Support for Collection Group Queries #15

Open elersong opened 3 months ago

elersong commented 3 months ago

Description

Firestore supports collection group queries, allowing you to search across multiple collections or subcollections with the same name. This feature is useful for querying data without needing to know the parent record. The proposed syntax for this feature in Fireorm is to use a collectionGroup function that derives the collection name from the entity.

Steps to Reproduce

  1. Attempt to query across subcollections with the same name using the current Fireorm implementation.
  2. Note the lack of support for collection group queries.

Expected Behavior

Ability to perform collection group queries using a syntax like collectionGroup(Entity).where(...).

Actual Behavior

Currently, Fireorm does not support collection group queries, limiting the ability to search across multiple collections or subcollections with the same name.

Acceptance Criteria

Additional Context

Proposed API Changes

  1. collectionGroup Function:

    • Introduce a collectionGroup function to support collection group queries.
    • Derive the collection group name from the entity name, similar to how collections are named when saved in the database.
    // Example usage
    const albumRepository = collectionGroup(Album);
    const album70s = albumRepository.whereLessThan('releaseDate', new Date('1980-01-01')).find();
  2. QueryBuilder Integration:

    • Use Fireorm's QueryBuilder to ensure type safety for the collection group queries.
    • Implement a light wrapper around collectionGroup and QueryBuilder to facilitate seamless integration and querying.
  3. Utility Function:

    • Consider implementing an intermediate utility function to extract the intended collection group name.
    • Ensure the utility function accurately derives the collection name from the entity, accommodating scenarios where an entity might belong to multiple collection groups.

Original Issue