Closed wellwelwel closed 4 weeks ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 90.32%. Comparing base (
6dccf55
) to head (a866100
). Report is 2 commits behind head on master.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Let's run some benchmarks before merging
@sidorares, I rewrote the logic and description of this PR.
Could you check again? 🙋🏻♂️
Using
Set
andhas
instead ofArray
andincludes
, due to:
Basic benchmark:
const arrayIncludes = (field) => {
console.time('Array.includes');
const privateObjectProps = [
'__defineGetter__',
'__defineSetter__',
'__lookupGetter__',
'__lookupSetter__',
'__proto__',
];
for (let i = 0; i < 1000000; i++) privateObjectProps.includes(field);
console.timeEnd('Array.includes');
};
const setHas = (field) => {
console.time('Set.has');
const privateObjectProps = new Set([
'__defineGetter__',
'__defineSetter__',
'__lookupGetter__',
'__lookupSetter__',
'__proto__',
]);
for (let i = 0; i < 1000000; i++) privateObjectProps.has(field);
console.timeEnd('Set.has');
};
for (let i = 0; i < 5; i++) arrayIncludes('field');
for (let i = 0; i < 5; i++) setHas('field');
Results:
Array.includes: 1.869ms
Array.includes: 0.621ms
Array.includes: 0.644ms
Array.includes: 0.658ms
Array.includes: 0.677ms
Set.has: 1.275ms
Set.has: 0.572ms
Set.has: 0.599ms
Set.has: 0.619ms
Set.has: 0.553ms
Compatibility:
Set
: Node.js 0.12.18.
Bringing a comment here: https://github.com/sidorares/node-mysql2/commit/74abf9ef94d76114d9a09415e28b496522a94805#r140992502 🤝
As suggested by @sidorares:
Instead of checking the field name manually, we have some alternatives:
results
object to a mapped objectObject.create(null)
by adding a config option to use a standard object for results (not sure about bump a major version for this)Although the issue #2585 doesn't have that many interactions, I think it's important to consider the users who don't participate directly 🙋🏻♂️
Also, if we consider the current solution, it's possible to return an empty object instead of throwing an error, as in mysqljs/mysql.
Merging this.
For a major release, I recommend reverting this PR and include a safer approach in docs, such as:
Object.hasOwn(row, 'column');
thank you so much for the solution
The previous solution (#2574) aimed to create a clean object, but it caused a major change.
Instead, I just grouped the object's private properties:
Then, it will perform a simple validation to ensure that the
fields[i].name
is safe:By this way, it's possible to:
prototype
after the query has been finished, they can