elersong / fireorm24

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

Option to Omit Sub-Collections from Queries #17

Open elersong opened 2 months ago

elersong commented 2 months ago

Description

There are scenarios where certain queries need to omit sub-collections, particularly when the data is being ingested by a third party. Providing a configuration option to disable sub-collection initialization on a per-request basis would be valuable.

Steps to Reproduce

  1. Perform a query using Fireorm that returns documents with sub-collections.
  2. Attempt to omit sub-collections from the query results without additional processing.

Expected Behavior

Ability to configure queries to exclude sub-collections from the results, either on a per-request basis or as a global setting.

Actual Behavior

Currently, sub-collections are always initialized, and developers must manually remove them if not needed.

Acceptance Criteria

Additional Context

Proposed API Changes

  1. Per-Request Configuration:

    • Add an optional parameter to query methods to disable sub-collection initialization.
    • Example:
      getRepository(Product).findById('1234', { initializeSubcollections: false });
  2. Global Configuration:

    • Introduce a global setting in the Fireorm initialization to disable sub-collection initialization for all queries.
    • Example:
      initialize({ initializeSubcollections: false });
  3. Default Behavior:

    • Ensure that sub-collection initialization is enabled by default to maintain backward compatibility.
    • Allow developers to override this behavior per query or for the entire project as needed.
  4. Implementation Considerations:

    • Ensure the implementation is clean and does not introduce significant overhead or complexity.
    • Provide clear documentation on how to use the new configuration options.

Example Usage

// Disable sub-collections for a specific query
const product = await getRepository(Product).findById('1234', { initializeSubcollections: false });

// Disable sub-collections globally
initialize({ initializeSubcollections: false });

Original Issue