mi sono imbattuto in questa domanda oggi come mi chiedevo la stessa cosa, e dopo un po 'più di ricerca mi sono imbattuto in Squel.
Citando direttamente dal loro sito web:
//this code
squel.select()
.from("students")
.field("name")
.field("MIN(test_score)")
.field("MAX(test_score)")
.field("GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')")
.group("name")
);
/* will return this SQL query as a string:
SELECT
name,
MIN(test_score),
MAX(test_score),
GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')
FROM
students
GROUP BY
name
*/
Speriamo che questo aiuterà tutti coloro che si imbatte in questa domanda durante la ricerca.
Buona fortuna!
PS: < diniego inserto standard di non generare query SQL nel browser ... >
Se si sta creando javascript client-side che invierà una query SQL al database si apre un intero vaso di Pandora - Se il browser può dettare la query SQL e un utente può manipolare ciò che proviene dal browser, allora è vulnerabile allo SQL injection attacks.
Bottom line: non usare questo nel browser!