Try to make the following SQL query using the node mysql2 package:
SELECT name, someObject->>"$.foo" as slice
FROM someTable;
The table someTable has 2 columns: name, a varchar; and someObject, a JSON column.
Imagine at least one row exists like this:
name someObject
==========================
John { "foo": "bar" }
The expected result of the query is:
name slice
==========================
John bar
Simply doing this works:
const result = await connection.query('SELECT name, someObject->>"$.foo" as slice FROM someTable');
However, I need the foo value escaped as it is user input. How to properly escape this?