planetarydev/json-sql-builder2

isValidIdent method question

rojoyin opened this issue · 2 comments

Hello,

I am sending this json

{
    "$select": {
        "$columns": ["day", "firstname", "lastname"],
        "$from": "a.b.1"
    }
}

As a result I got:

{
  "sql": "SELECT day, firstname, lastname FROM a.b.\"1\"",
  "values": []
}

What I was expecting was:

{
  "sql": "SELECT day, firstname, lastname FROM a.b.1",
  "values": []
}

The point in the code that changes what I expected is in the following validation.

isValidIdent(identifier){
return /^[a-z_][a-z0-9_$]*$/.test(identifier) === true && !this._reservedWords[identifier.toUpperCase()];
}

Is there any reason the identifier must not begin with numbers?

I could fix it, if there is no problem in changing this condition.

Best regards.

My major System is postgres and there it is Not allowed. You can fix it in condition to the specific System you need. Or a netter way is to implement an option for that.

I solved by using the function setQuoteChar passing the parameter with value ''
Thank you