NOTE: It is recommended that you do NOT create queries browser-side to run on the server as this massively increases your exposure to SQL Injection attacks.
Again. If such a disclaimer needs to be added at the top of your website, is it really a good idea to proceed, then? But it may be for the node.js folks. So let’s have a look at the syntax of Squel.
Does this look familiar? So far, it could also be jOOQ code. With this SQL builder API, you can also create select from derived tables:
alert( squel.select() .from(squel.select().from('students'), 's') .field('s.id') ); /* SELECT s.id FROM (SELECT * FROM students) `s` */
Or perform JOINs:
alert( squel.select() .field("students.id") .from("students") .left_join("teachers", null, "students.id = teachers.student_id") .right_join("jailed", "j", "j.student_id = students.id") ); /* SELECT students.id FROM students LEFT JOIN teachers ON (students.id = teachers.student_id) RIGHT JOIN jailed `j` ON (j.student_id = students.id) */
Obviously, unlike Java SQL builders, this API is not typesafe, but it’s still interesting to see fluent APIs in other languages as well.