Skip to content

Mila/count add api interface#6499

Merged
milaGGL merged 5 commits intomila/countfrom
mila/count-add-API-interface
Aug 4, 2022
Merged

Mila/count add api interface#6499
milaGGL merged 5 commits intomila/countfrom
mila/count-add-API-interface

Conversation

@milaGGL
Copy link
Copy Markdown
Contributor

@milaGGL milaGGL commented Aug 3, 2022

This count query interface is implemented based on the COUNT Query API proposal.

Based on the demo provided:

async function Demo1_CountOfDocumentsInACollection(db: Firestore) {
  const countQuery_ = countQuery(collection(db, "games/halo/players"));
  const snapshot = await getAggregateFromServerDirect(countQuery_);
  expect(snapshot.getCount()).to.equal(5000000);
}

async function Demo2_CountOfDocumentsInACollectionWithFilter(db: Firestore) {
  const query_ = query(collection(db, "games/halo/players"), where("online", "==", true));
  const countQuery_ = countQuery(query_);
  const snapshot = await getAggregateFromServerDirect(countQuery_);
  expect(snapshot.getCount()).to.equal(2000);
}
  • countQuery function will accept a collection or query reference
  • countQuery will create a aggregateQuery instance, and return it. (class AggregateQuery)
  • getAggregateFromServerDirect function will take aggregateQuery object, create AggregateQuerySnapshot instance, and return a promise
  • AggregateQuerySnapshot object has getCount public method to access the document count

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Aug 3, 2022

⚠️ No Changeset found

Latest commit: 0a2f104

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@milaGGL milaGGL changed the base branch from master to mila/count August 3, 2022 00:46
@@ -17,6 +17,30 @@ export type AddPrefixToKeys<Prefix extends string, T extends Record<string, unkn
[K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
};

Copy link
Copy Markdown
Contributor Author

@milaGGL milaGGL Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-updated file by API Extractor

import {DocumentData, Query, queryEqual} from './reference';


export class AggregateQuery<T = DocumentData>{
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created class only, hasn't implement the internal methods

Comment thread packages/firestore/src/lite-api/aggregate.ts
@google-oss-bot
Copy link
Copy Markdown
Collaborator

google-oss-bot commented Aug 3, 2022

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (598e948)Merge (52d3f9c)Diff
    browser264 kB264 kB+547 B (+0.2%)
    esm5327 kB327 kB+579 B (+0.2%)
    main526 kB528 kB+1.41 kB (+0.3%)
    module264 kB264 kB+547 B (+0.2%)
    react-native264 kB264 kB+547 B (+0.2%)
  • firebase

    TypeBase (598e948)Merge (52d3f9c)Diff
    firebase-firestore.js851 kB853 kB+1.35 kB (+0.2%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/MIflKVxzUv.html

@google-oss-bot
Copy link
Copy Markdown
Collaborator

google-oss-bot commented Aug 3, 2022

query
} from '../util/firebase_export';
import { apiDescribe, withTestCollection } from '../util/helpers';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both tests will fail as the count API internal logic is not implemented yet, and only returning 42 as dummy count.

@dconeybe dconeybe removed their assignment Aug 4, 2022
@milaGGL milaGGL merged commit 7f42490 into mila/count Aug 4, 2022
@milaGGL milaGGL deleted the mila/count-add-API-interface branch August 4, 2022 16:57
@firebase firebase locked and limited conversation to collaborators Sep 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants