You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
builder.conditionalHelpers.add('$regex',(column,value)=>column+" REGEXP "+value);builder.conditionalHelpers.add('$options',(_,__,values)=>{values.pop();// remove current value from array});constsql=builder.sql({type: 'delete',table: 'users',where: {created_at: {$regex: 5,$options: 'i'}}});
{query: 'delete from "users" where "users"."created_at" REGEXP $1 and',values: [5],original: {type: 'delete',table: 'users',where: {created_at: [Object]},__defaultTable: 'users'},toString: [Function],toQuery: [Function]}
Notice how the question ends with and (invalid SQL syntax) and how I am completely unable to process the "ignore case" option.
Solution
In the code, the helper function is invoked like this :
The entire filter context would be available, including the helper value. Such as
builder.conditionalHelpers.add('$regex',(column,value,_,filter)=>{// NOTE : filter.$regex is the same as before; we know what the 'key' value is!constisCaseInsensitive=checkOptions(filter.$options);if(isCaseInsensitive){return"LOWER("+column+") REGEXP "+value;}else{returncolumn+" REGEXP "+value;}});
Also
The values should not be pushed to the array before the helper function returns, and the helper function returned value should not be undefined. For example :
Problem
The current implementation makes it impossible to implement the
$regex
conditional helper. From the documentation :I tried implementing it with :
Notice how the question ends with
and
(invalid SQL syntax) and how I am completely unable to process the "ignore case" option.Solution
In the code, the helper function is invoked like this :
mongo-sql/lib/condition-builder.js
Lines 54 to 60 in 7c0172c
Passing (arguably) the same value
where[key]
in two different arguments. The function helper does not needwhere[key]
, however it does needwhere
.Therefore, if the helper function was called like this :
The entire filter context would be available, including the helper value. Such as
Also
The
values
should not be pushed to the array before the helper function returns, and the helper function returned value should not beundefined
. For example :So, the above implementation should not produce
but should produce
That is, ignore
$options
completely, and do not push it's value to thevalues
list.The text was updated successfully, but these errors were encountered: