Skip to content

Refactor Transaction and Dataset into DatastoreRequest#231

Closed
ryanseys wants to merge 9 commits intogoogleapis:masterfrom
ryanseys:refactor-transaction-dataset
Closed

Refactor Transaction and Dataset into DatastoreRequest#231
ryanseys wants to merge 9 commits intogoogleapis:masterfrom
ryanseys:refactor-transaction-dataset

Conversation

@ryanseys
Copy link
Contributor

Might be missing documentation in a few areas because I wanted to get the structural changes out first before we refine it.

Separates the request logic out from Dataset and Transaction into a DatastoreRequester which probably isn't the best name but can be refactored as well. Feel free to send suggestions.

@ryanseys
Copy link
Contributor Author

regression test should run in a transaction is failing right now 👎 I also have to head out for the weekend, but I might get some time to look into it. In the meantime if someone can take a look at this, that'd be great 😄 Just do not merge!!

@stephenplusplus
Copy link
Contributor

Just linking these together for us: #204

Thoughts so far:

  • Transaction will either have to overwrite createRequest, or DatastoreRequester.createRequest will have to allow more customization. Thinking ahead for GAE dev support, we will have to set a port & host, and perhaps handle other things within that function just a little differently.
  • Should Dataset.prototype.allocateIds be on the DatastoreRequester object?

Overall, I like the separation. We should make sure this structure is 👍 so that we can mimic it throughout the codebase as we go on supporting the other services.

To support that goal, is there a way we could make an even more abstract ApiRequest class that could handle some common things, like ApiRequest.prototype.getRemoteStream, which would take a request and callback that gets executed on end:

var remoteStream = https.request(request, function(resp) {
  var buffer = new Buffer('');
  resp.on('data', function(chunk) {
    buffer = Buffer.concat([buffer, chunk]);
  });
  resp.on('end', function() {
    util.handleResp(null, resp, buffer.toString(), function(err) {
      if (err) {
        cb(err);
        return;
      }
      cb(null, respType.decode(buffer));
    });
  });
});
remoteStream.on('error', cb);
remoteStream.write(req.toBuffer());
remoteStream.end();

Something like:

| ApiRequest.prototype.createRequest
| ApiRequest.prototype.getRemoteStream
|
|__ DatastoreRequest.prototype.allocateIds
|__ DatastoreRequest.prototype.delete
|__ DatastoreRequest.prototype.get
|__ DatastoreRequest.prototype.runQuery
|__ DatastoreRequest.prototype.save
|
|__ Transaction.prototype.begin
|__ Transaction.prototype.commit
|__ Transaction.prototype.finalize
|__ Transaction.prototype.rollback
|
|__ Bucket.prototype.copy
|__ Bucket.prototype.list
|__ Bucket.prototype.remove
|__ Bucket.prototype.stat

Any of these sub-classes can implement their own createRequest if necessary.

@ryanseys
Copy link
Contributor Author

Yes that would be ideal, to separate into a common module that can be used across all APIs. DatastoreRequester is a terrible name. Maybe all of DatastoreRequester can go into Datastore once we move the request logic out into ApiRequest

@ryanseys
Copy link
Contributor Author

Having any class have to create a new createRequest is basically necessary here because we are doing different stuff with the results for every different API. That's why I'm hesistant to extract it further than Datastore because I don't think much can be gained from it.

@stephenplusplus
Copy link
Contributor

There is still a benefit to abstracting some commonalities, such as creating streams, handling errors/responses, creating authenticated requests, etc. but it's ok to put this off for now. If we think we need to abstract later, we can revisit that then.

Are there any changes you want to make to this pr or is it ready for review?

@ryanseys
Copy link
Contributor Author

Yes. I agree. It's important to pull out the streaming stuff and some common entities but it's beyond the scope of this PR.

@ryanseys
Copy link
Contributor Author

I changed DatastoreRequester to DatastoreRequest and fixed small transaction bug so I think this is ready for more formal review. 😄 thanks!

@stephenplusplus
Copy link
Contributor

Should Dataset.prototype.allocateIds be on the DatastoreRequest object?

@stephenplusplus
Copy link
Contributor

I like it, but I think we're going to have a tough time working this into the docs. Atm, the only thing I can think of is having a new docs page for the DatastoreRequest module that is linked to from Dataset.

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

How about request.js instead of datastore_request.js? We have the datastore directory name that can keep it hierarchically clear. (we don't have datastore_transaction.js, datastore_dataset.js for example)

@ryanseys
Copy link
Contributor Author

sure just as long as we don't confuse it with request library

@stephenplusplus
Copy link
Contributor

We can still name it in a way that's helpful locally, if you think something like this is better:

var DatastoreRequest = require('./request.js');

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

sofisl pushed a commit that referenced this pull request Nov 18, 2022
sofisl pushed a commit that referenced this pull request Jan 10, 2023
sofisl pushed a commit that referenced this pull request Sep 13, 2023
miguelvelezsa pushed a commit that referenced this pull request Jul 23, 2025
GautamSharda pushed a commit that referenced this pull request Jan 14, 2026
GautamSharda pushed a commit that referenced this pull request Jan 20, 2026
GautamSharda pushed a commit that referenced this pull request Jan 21, 2026
miguelvelezsa pushed a commit that referenced this pull request Jan 29, 2026
…ncy versions (#231)

This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/a1c25589-9aeb-49f0-922e-4037066a83df/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@fdd03c1
GautamSharda pushed a commit that referenced this pull request Feb 2, 2026
sofisl pushed a commit that referenced this pull request Feb 3, 2026
* chore(deps): upgrade @google-cloud/paginator to v0.1.2

* fix(system-test): filter by label when testing pagination
GautamSharda pushed a commit that referenced this pull request Feb 3, 2026
sofisl pushed a commit that referenced this pull request Feb 4, 2026
GautamSharda pushed a commit that referenced this pull request Feb 5, 2026
* build: run tests on node11

* build: run tests on node11

* build: run tests on node11

* build: run tests on node11
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.

3 participants