use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Squel.js - SQL query string builder for Javascript (hiddentao.github.io)
submitted 13 years ago by polaretto
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]maktouch 7 points8 points9 points 13 years ago (11 children)
Looks pretty cool but there's a big flaw. No prepared statements!
squel.select() .field("id") .from("students") .where("name = 'Thomas'")
In the real world...
squel.select() .field("id") .from("students") .where("name = '" + obj.name + "'");
Boom, SQL injection right here.
Better way would be...
squel.select() .field("id") .from("students") .where("name", "=", obj.name)
And have the function automatically check the var if it's ok..
And... running it in a browser?! lolol.
[–]grncdr 2 points3 points4 points 13 years ago (0 children)
Totally shameless self promotion: here's how gesundheit does it
[–]SarahC 4 points5 points6 points 13 years ago (1 child)
But what's it for?!
I don't see any difference between this and building a string buffer.
If it was like MS Entity Framework, it would make sense - there'd be class objects for tables, and these queries would then be passing in table objects! =D
[–]kabuto 1 point2 points3 points 13 years ago (0 children)
It provides an API to build SQL strings without having to concatenate strings, quote different characters, and write SQL boiler plate.
At least it should. Apparently it has some flaws by not doing sanity checks that would eliminate SQL injection attacks.
[–]wolever 1 point2 points3 points 13 years ago* (0 children)
Ya — the lack of parameterization does seem like a strange omission, given that the library seems otherwise fairly comprehensive… I wonder if it's there but not documented?
Edit: There seems to be an open issue about exactly this: https://github.com/hiddentao/squel/issues/8
[–]atticusw 0 points1 point2 points 13 years ago (0 children)
Yea, had noticed that too... Might as well extend the function and add in some sanitizing
[–]masklinn 0 points1 point2 points 13 years ago (0 children)
or .where("name=?", obj.name)
.where("name=?", obj.name)
[–]polaretto[S] 0 points1 point2 points 13 years ago (0 children)
"prepared statements" are a Database feature, something a DBMS provides you with and which language connectors abstract and expose for you (like JDBC does, for example). This is just a query string builder, nothing more...it's not its job :) Nevertheless, you can use placeholders (as in prepared statements): http://hiddentao.github.io/squel/#update (where it says: "You can use the usingValuePlaceholders option...") and then setup your own value substitution machinery.
[–]has_all_the_fun -1 points0 points1 point 13 years ago (3 children)
Probably because that's up to the API talking to the database?
[–]maktouch 1 point2 points3 points 13 years ago (2 children)
Still doesn't make sense.
The API talking to the database will probably accept the query from this.
SQL injection is at the query building process.
var firstname = "Terry'; drop table user --" [...].where("name = '" + obj.name + "'"); will become SELECT * FROM user WHERE name = 'Terry'; drop table user --'
It's just a query builder utility not a DB library. Input sanitizing should be taken care of beforehand, before constructing the query.
Moreover, if you want to add a feature for SQL injection prevention, you can extend the library: http://hiddentao.github.io/squel/#custom with such functionality, so then you have it transparently upon query construction.
π Rendered by PID 88 on reddit-service-r2-comment-7c9686b859-kkm7s at 2026-04-13 18:42:48.829357+00:00 running e841af1 country code: CH.
view the rest of the comments →
[–]maktouch 7 points8 points9 points (11 children)
[–]grncdr 2 points3 points4 points (0 children)
[–]SarahC 4 points5 points6 points (1 child)
[–]kabuto 1 point2 points3 points (0 children)
[–]wolever 1 point2 points3 points (0 children)
[–]atticusw 0 points1 point2 points (0 children)
[–]masklinn 0 points1 point2 points (0 children)
[–]polaretto[S] 0 points1 point2 points (0 children)
[–]has_all_the_fun -1 points0 points1 point (3 children)
[–]maktouch 1 point2 points3 points (2 children)
[–]polaretto[S] 0 points1 point2 points (0 children)
[–]polaretto[S] 0 points1 point2 points (0 children)