elersong / fireorm24

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

Implement Select Method for Partial Document Retrieval #22

Open elersong opened 2 months ago

elersong commented 2 months ago

Description

Firebase Firestore has a select method that allows retrieving specific fields from a document, similar to the SELECT statement in SQL. This feature can be beneficial for improving performance by reducing the amount of data transferred over the network. Currently, Fireorm does not support this feature.

Steps to Reproduce

  1. Attempt to use the select method in Fireorm to retrieve specific fields from a document.
  2. Notice that the feature is not implemented.

Expected Behavior

Ability to use a select method to specify which fields to retrieve from a document, reducing the amount of data transferred and improving performance.

Actual Behavior

Fireorm always returns the entire document, which can lead to unnecessary data transfer and performance issues.

Acceptance Criteria

Additional Context

Proposed API Changes

  1. Introduce Select Method:

    • Add a select method to the repository that allows specifying which fields to retrieve.
    // Example usage
    const partialUser = await getRepository(User).select('display_name', 'username').findById(userId);
  2. Type-Safe API:

    • Ensure that the select method is type-safe, providing autocomplete and type checking for field names.
  3. Implementation Details:

    • Modify the query builder to support the select method.
    • Ensure that the select method integrates seamlessly with existing query methods in Fireorm.
    • Provide thorough testing to validate the new functionality and ensure it does not introduce any regressions.

Example Implementation

@Collection()
class User {
  id: string;
  display_name: string;
  username: string;
  email: string;
}

// Repository instance
const repo = getRepository(User);

// Retrieve only specific fields
const partialUser = await repo.select('display_name', 'username').findById(userId);

Original Issue