Skip to content

Conversation

@GochoMugo
Copy link

Which problem is this PR solving?

When using sql-templating libraries such as sql-template-strings, the query object is usually not a plain object, and instead a class instance.

An extracted snippet:

class SQLStatement {
  constructor(strings, values) {
    this.strings = strings
    this.values = values
  }

  /** Returns the SQL Statement for node-postgres */
  get text() {
    return this.strings.reduce((prev, curr, i) => prev + '$' + i + curr)
  }

  setName(name) {
    this.name = name
    return this
  }
}

function SQL(strings) {
  return new SQLStatement(strings.slice(0), Array.from(arguments).slice(1))
}

This class would be instantiated, for example, when using template string:

client.query(SQL`select ...`);

With the changes added in PR #3196, the text property from the Statement class above would not be captured when using the spread operator i.e. { ...arg0 }.

For example,

class Klass {
  constructor() {
    this.foo = 1;
  }
  get bar() {
    return 2;
  }
}
const instance = new Klass();
const obj = { ...instance };

assert(obj.foo === 1);
assert(obj.bar === undefined); // `bar` is not set!

Short description of the changes

The current fix is to explicitly capture name and text props while still using the spread operator.

@GochoMugo GochoMugo requested a review from a team as a code owner November 26, 2025 08:03
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 26, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

});
});

it('should record query and values for prepared statements', done => {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of updating this test, can you add a new one, this way we can check changes work with both scenarios?

Copy link
Author

Choose a reason for hiding this comment

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

@maryliag Addressed in commit b8524b1.

@GochoMugo GochoMugo force-pushed the fix/pg-instrumentation branch from 1ad024e to b8524b1 Compare November 28, 2025 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants