metarhia/metasql

Break the loop when the sql operator has been found.

mapogolions opened this issue · 2 comments

At the moment, when operator has been found the loop continues its work. Please, take a look at the following piece of code

value = value.substring(len);

As a result, if you pass the below input to the function, the last operator (<=) will be resolved.

const { clause } = where({ age: '>=<=18' });
console.log(clause); // 'age <='

Maybe in this case it makes sense to use the break statement.

@mapogolions Can't understand, maybe you can explain in Russian here: https://github.com/metarhia/metasql/discussions

@tshemsedinov from what I understand

for (const op of OPERATORS) {

this loop keeps running even after value is found. in his example, if you pass >=, it finds it on the first iteration, but the loop does not stop. it keeps going till it iterates over all OPERATORS.
I think breaking the loop makes sense. if not, can you explain why?