Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add read-only transactions #1541

Merged
merged 7 commits into from
Jun 29, 2021
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

This adds read-only transactions to Firestore Node. They are already available in Java.

Fixes #1245

@schmidt-sebastian schmidt-sebastian requested review from a team as code owners June 23, 2021 20:29
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Jun 23, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 23, 2021
* document. A transaction releases its document locks at commit time or if
* it fails for any reason.
*
* Read-only transaction do not lock documents. They can be used to read

Choose a reason for hiding this comment

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

s/transaction/transactions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

dev/src/index.ts Outdated
* writes, and other non-transactional writes from changing that document.
* A transaction releases its document locks at commit time or once it times
* out or fails for any reason.
* Transaction can be performed as read-only or read-write transactions. By

Choose a reason for hiding this comment

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

s/Transaction/Transactions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


readOnly = true;
readTime = transactionOptions.readTime as Timestamp | undefined;
maxAttempts = 1;

Choose a reason for hiding this comment

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

optional: specify that read-only transactions not retried in the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (might make sense for you to do a quick sanity check on the result)

expect(snapshot.get('foo')).to.equal(1);
});

it('fails read-only with writes', async () => {

Choose a reason for hiding this comment

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

optional: verify that the tx was not retried.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Sebastian goes above and beyond"

@@ -174,6 +174,28 @@ declare namespace FirebaseFirestore {
[key: string]: any; // Accept other properties, such as GRPC settings.
}

/** Options to configure a read-only transaction. */
export interface ReadOnlyTransactionOptions {
/** Set to true to indicate a read-write transaction. */

Choose a reason for hiding this comment

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

s/read-write/read-only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


/** Options to configure a read-write transaction. */
export interface ReadWriteTransactionOptions {
/** Set to false or omitted to start a read-write transaction. */

Choose a reason for hiding this comment

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

s/start/indicate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@schmidt-sebastian schmidt-sebastian merged commit ca4241e into master Jun 29, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/readonly branch June 29, 2021 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to use read-only transactions
2 participants