Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Support Knex#468

Merged
DominicKramer merged 14 commits intogoogleapis:masterfrom
DominicKramer:feature/support-knex
May 23, 2017
Merged

Support Knex#468
DominicKramer merged 14 commits intogoogleapis:masterfrom
DominicKramer:feature/support-knex

Conversation

@DominicKramer
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

PTAL

Copy link
Copy Markdown
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).

Comment thread test/plugins/test-trace-knex.js Outdated
databaseResultReportingSize: RESULT_SIZE
});
assert = require('assert');
knex = require('./fixtures/knex0.12')({

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/plugins/plugin-bluebird.js Outdated
}

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

This comment was marked as spam.

This comment was marked as spam.

@DominicKramer DominicKramer force-pushed the feature/support-knex branch from 425818b to 6010c4b Compare May 4, 2017 19:37
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.

Comment thread src/plugins/plugin-knex.js Outdated
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.

Comment thread src/plugins/plugin-knex.js Outdated
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.
@DominicKramer DominicKramer force-pushed the feature/support-knex branch from 80d3264 to aa7279a Compare May 13, 2017 00:04
Comment thread src/plugins/plugin-knex.js Outdated
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.

Comment thread src/plugins/plugin-knex.js Outdated

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
Copy Markdown
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).

Comment thread test/plugins/test-trace-knex.js Outdated
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 <[email protected]>
Date:   Mon Apr 6 16:17:34 2020 -0700

    fix: apache license URL (#468)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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