[erlang-questions] Mysql Query builder lib in Erlang?

28 views
Skip to first unread message

Vineet Naik

unread,
Apr 2, 2013, 7:47:52 AM4/2/13
to erlang-q...@erlang.org
Hi, 

Is there a mysql query builder library for Erlang? On some searching, 
I came across boss_db[1] which is an ORM. While I am open to ORMs and 
planning to give it a try, I would prefer a simple query builder


Regards,
Vineet

Dmitry Kolesnikov

unread,
Apr 2, 2013, 7:59:57 AM4/2/13
to Vineet Naik, erlang-q...@erlang.org
Hi,

I've made Erlang port of whiskers.js template library

as a side effect is become a client-side SQL query template builder, which I've started to use for my project.

Here is a small example:

swirl:c(mysql, "SELECT * FROM Users WHERE id={id}").
mysql:render([{id, "xxx"}]).
"SELECT * FROM Users WHERE id=xxx"

- Dmitry 


_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Loïc Hoguin

unread,
Apr 2, 2013, 8:00:50 AM4/2/13
to Dmitry Kolesnikov, erlang-q...@erlang.org
mysql:render([{id, "'' or 1=1 --"}]).

On 04/02/2013 01:59 PM, Dmitry Kolesnikov wrote:
> Hi,
>
> I've made Erlang port of whiskers.js template library
> https://github.com/fogfish/swirl
>
> as a side effect is become a client-side SQL query template builder,
> which I've started to use for my project.
>
> Here is a small example:
>
> swirl:c(mysql, "SELECT * FROM Users WHERE id={id}").
> mysql:render([{id, "xxx"}]).
> "SELECT * FROM Users WHERE id=xxx"
>
> - Dmitry
>
>
> On Apr 2, 2013, at 2:47 PM, Vineet Naik <nai...@gmail.com
> <mailto:nai...@gmail.com>> wrote:
>
>> Hi,
>>
>> Is there a mysql query builder library for Erlang? On some searching,
>> I came across boss_db[1] which is an ORM. While I am open to ORMs and
>> planning to give it a try, I would prefer a simple query builder
>>
>> [1]: https://github.com/evanmiller/boss_db
>>
>> Regards,
>> Vineet
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-q...@erlang.org <mailto:erlang-q...@erlang.org>
>> http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-q...@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions
>


--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu

Dmitry Kolesnikov

unread,
Apr 2, 2013, 8:06:55 AM4/2/13
to Loïc Hoguin, erlang-q...@erlang.org
You are welcome to patch it!!!

as I said this is Erlang port of whiskers.js template library.
all aspects of SQL injection must be handled before *:render is called.

- Dmitry

Vineet Naik

unread,
Apr 2, 2013, 8:19:51 AM4/2/13
to Dmitry Kolesnikov, erlang-q...@erlang.org
On Tue, Apr 2, 2013 at 5:29 PM, Dmitry Kolesnikov <dmkole...@gmail.com> wrote:
Hi,

I've made Erlang port of whiskers.js template library

as a side effect is become a client-side SQL query template builder, which I've started to use for my project.

Here is a small example:

swirl:c(mysql, "SELECT * FROM Users WHERE id={id}").
mysql:render([{id, "xxx"}]).
"SELECT * FROM Users WHERE id=xxx"

This is an interesting approach but not exactly what I am looking for. 
I am searching for an alternative to writing raw queries in code.

I have one idea ie. to express the query may be using tuples and lists. and have a
set of functions transform it to sql. Not sure if this will make things more complicated
though :-) but it's just an idea.

Thanks,
vineet

Fred Hebert

unread,
Apr 2, 2013, 8:30:22 AM4/2/13
to Dmitry Kolesnikov, erlang-q...@erlang.org
Then I would not advertise it as a way to template SQL. This is
dangerous for any reader who felt the urge to use the whikers.js port to
handle SQL, as there is absolutely no protection against one of the
biggest attack vectors out there.

nx

unread,
Apr 2, 2013, 8:52:20 AM4/2/13
to Vineet Naik, erlang-questions
I remember coming across erlsql while checking out the erlyweb project a while back: https://github.com/yariv/erlyweb/blob/master/src/erlsql/erlsql.erl.


Vineet Naik

unread,
Apr 2, 2013, 10:44:55 PM4/2/13
to nx, erlang-questions
erlsql.erl looks good. I will give it a try. Thanks
--
Vineet Naik

Reply all
Reply to author
Forward
0 new messages