Skip to content

DML prototype#9490

Open
wu-hui wants to merge 1 commit intomainfrom
push-wnxmktpmntwo
Open

DML prototype#9490
wu-hui wants to merge 1 commit intomainfrom
push-wnxmktpmntwo

Conversation

@wu-hui
Copy link
Contributor

@wu-hui wu-hui commented Feb 11, 2026

No description provided.

@wu-hui wu-hui requested review from a team as code owners February 11, 2026 14:29
@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2026

⚠️ No Changeset found

Latest commit: b4e31ac

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @wu-hui, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Firestore pipeline API by integrating Data Manipulation Language (DML) capabilities. It allows users to perform delete, upsert, and insert operations directly within a pipeline, providing a more powerful and streamlined way to modify data based on pipeline results. This change expands the utility of the pipeline for complex data workflows.

Highlights

  • New DML Stages: Introduced Delete, Upsert, and Insert stages to the Firestore pipeline, enabling direct data manipulation operations.
  • Pipeline API Extensions: Added delete(), upsert(), and insert() methods to the Pipeline class, allowing users to perform DML operations on documents processed by the pipeline.
  • New Stage Options: Defined WriteStageOptions, DeleteStageOptions, UpsertStageOptions, and InsertStageOptions to configure the behavior of the new DML stages, including options for transactional behavior, return values, collection targets, and conflict resolution.
  • Integration Tests: Included comprehensive integration tests to validate the functionality and various options of the new DML pipeline operations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/firestore/src/lite-api/pipeline.ts
    • Imported new DML stage types (Delete, Upsert, Insert) and their corresponding options.
    • Added CollectionReference import for DML operations.
    • Implemented delete(), upsert(), and insert() methods to the Pipeline class, each handling user data parsing and stage addition.
  • packages/firestore/src/lite-api/stage.ts
    • Imported Selectable and selectablesToMap for potential future use in DML stages.
    • Defined new Delete, Upsert, and Insert classes, each extending Stage and implementing specific logic for their respective DML operations, including option parsing and proto serialization.
  • packages/firestore/src/lite-api/stage_options.ts
    • Introduced WriteStageOptions as a base type for DML operations, including a transactional option.
    • Defined DeleteStageOptions with a returns option.
    • Defined UpsertStageOptions with collection, returns, conflictResolution, and transformations options.
    • Defined InsertStageOptions with collection, returns, and transformations options.
  • packages/firestore/test/integration/api/pipeline.test.ts
    • Added a new test suite specifically for 'DML operations'.
    • Included integration tests for the delete() method, verifying basic execution and options like returns and transactional.
    • Added integration tests for the upsert() method, covering various ways to specify the target collection and options like conflictResolution.
    • Implemented integration tests for the insert() method, checking execution with collection references and options.
Activity
  • The pull request introduces new Data Manipulation Language (DML) features to the Firestore pipeline.
  • New Delete, Upsert, and Insert stages have been defined, along with their respective options.
  • The Pipeline class has been extended with methods to allow users to invoke these new DML stages.
  • Integration tests have been added to ensure the correct functionality of the new DML operations within the pipeline.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces DML operations (delete, upsert, insert) as new stages in the Firestore pipeline prototype, which is a great extension of its capabilities. The implementation looks solid, adding the necessary stage classes, options, and methods to the Pipeline class.

I've left a few comments with suggestions for improvement:

  • In pipeline.ts, the type check for CollectionReference in upsert() and insert() methods is a bit brittle and can be made more robust and readable by using the isCollectionReference type guard.
  • In stage.ts, there's some code duplication in the Upsert and Insert stage classes (both in the constructor and _toProto method). This could be refactored into a common base class or a helper function to improve maintainability.

Comment on lines +1558 to +1561
typeof collectionOrOptions === 'string' ||
(typeof collectionOrOptions === 'object' &&
'type' in collectionOrOptions &&
collectionOrOptions.type === 'collection')
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The type check for CollectionReference is a bit brittle and is duplicated in the insert method below. It can be simplified and made more robust by using the isCollectionReference type guard, which is exported from ./reference.

For example, if collectionOrOptions is null, typeof collectionOrOptions is 'object', which would cause a TypeError on the 'type' in collectionOrOptions check.

You'll need to import isCollectionReference from ./reference to use it.

      typeof collectionOrOptions === 'string' ||
      isCollectionReference(collectionOrOptions)

Comment on lines +806 to +846
export class Upsert extends Stage {
get _name(): string {
return 'upsert';
}

get _optionsUtil(): OptionsUtil {
return new OptionsUtil({
transactional: { serverName: 'transactional' },
returns: { serverName: 'returns' },
conflictResolution: { serverName: 'conflict_resolution' }
});
}

constructor(options: StageOptions) {
super(options);

if ('collection' in this.knownOptions && typeof this.knownOptions.collection === 'string') {
const collection = this.knownOptions.collection;
this.knownOptions.collection = collection.startsWith('/') ? collection : '/' + collection;
}
}

/**
* @internal
* @private
*/
_toProto(serializer: JsonProtoSerializer): ProtoStage {
let args: any[] = [];
if (this.knownOptions.collection) {
args.push({ referenceValue: this.knownOptions.collection });
}
return {
...super._toProto(serializer),
args
};
}

_readUserData(context: ParseContext): void {
super._readUserData(context);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Upsert and Insert classes share identical logic for normalizing the collection path in their constructors and for serializing the collection option in their _toProto methods. This duplication can be avoided by extracting the common logic into a shared base class (e.g., CollectionMutationStage) that both Upsert and Insert can extend. This would improve maintainability and reduce code redundancy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant