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

Support Knex #468

Merged
merged 14 commits into from
May 23, 2017
Merged

Conversation

DominicKramer
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 14, 2017
@DominicKramer
Copy link
Contributor Author

PTAL

Copy link
Contributor

@matthewloring matthewloring left a comment

Choose a reason for hiding this comment

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

It looks good overall but I agree that we should understand what async work is being done by knex to cause this context loss (even though this bluebird patch does fix this problem).

databaseResultReportingSize: RESULT_SIZE
});
assert = require('assert');
knex = require('./fixtures/knex0.12')({

This comment was marked as spam.

This comment was marked as spam.

}

function patchPromise(Promise, api) {
shimmer.wrap(Promise.prototype, '_addCallbacks', function(original) {

This comment was marked as spam.

This comment was marked as spam.

shimmer.wrap(Client.prototype, 'runner', function(original) {
return function() {
var runner = original.apply(this, arguments);
runner.query = api.wrap(runner.query);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

function interceptKnex(Knex, api) {
return function() {
var result = Knex.apply(this, arguments);
var proto = Object.getPrototypeOf(result.client);

This comment was marked as spam.

This comment was marked as spam.

var proto = Object.getPrototypeOf(result.client);
shimmer.wrap(proto, 'transaction', function(original) {
return function() {
var args = Array.prototype.slice.call(arguments).map(function(item) {

This comment was marked as spam.

This comment was marked as spam.

I think this patch is specific to mysql.  I will investigate this
further.
This commit intercepts the module root to patch the `transaction`
method.  This works because the `knex` module exports a
constructor and the object that the constructor constructs has a
`client` property that is the client being used.  This client
can have its `transaction` method updated in a way to preserve
context.
var util = require('util');
var is = require('is');

var VERSIONS = '0.12.x';

This comment was marked as spam.

This comment was marked as spam.


function interceptTransaction(Transaction, api) {
function WrappedTransaction(client, container, config, outerTx) {
Transaction.call(this, client, wrapIfFn(container, api), config, outerTx);

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

@matthewloring matthewloring left a comment

Choose a reason for hiding this comment

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

LGTM with nit once appveyor and circle are passing (travis failures are unrelated).

enhancedDatabaseReporting: true,
databaseResultReportingSize: RESULT_SIZE
});
assert = require('assert');

This comment was marked as spam.

This comment was marked as spam.

@DominicKramer DominicKramer merged commit dd7bc9b into googleapis:master May 23, 2017
vmarchaud pushed a commit to keymetrics/trassingue that referenced this pull request Jun 1, 2017
This commit includes support and tests for knex satsifying `>=0.10 <=0.13`.

PR-URL: googleapis/cloud-trace-nodejs#468
yoshi-automation added a commit that referenced this pull request Apr 7, 2020
googleapis/synthtool@1df68ed
commit 1df68ed6735ddce6797d0f83641a731c3c3f75b4
Author: Alexander Fenster <fenster@google.com>
Date:   Mon Apr 6 16:17:34 2020 -0700

    fix: apache license URL (#468)
gcf-merge-on-green bot pushed a commit that referenced this pull request Apr 7, 2020
Mistic92 pushed a commit to Mistic92/cloud-trace-nodejs that referenced this pull request Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants