[erlang-questions] [ANN] Asynchronous PostgreSQL driver

Dmitry Demeshchuk demeshchuk@REDACTED
Tue Nov 1 08:59:58 CET 2011


On Tue, Nov 1, 2011 at 10:16 AM, Max Lapshin <max.lapshin@REDACTED> wrote:
> Anton, haven't you looked at modern mysql drivers? Maybe there is some
> code to share, like connection pool.

Just to mention, I have a small library that implements pools:
https://github.com/doubleyou/gen_pool . Feel free to use it.

>
> And also: I think it would be really very convenient to have something
> like implicit connection:
>
>
> epgsql:establish_connection(...)
>
> {ok, Result} = epgsql:query("SELECT * FROM articles ..");
>
>
> Usually you are working with single database and perhaps it would be
> good to have API for implicit singleton database connection.
> Passing established connection to database through all levels of
> business logic may be rather inconvenient sometimes and often
> ends in having global variables.

Or, rather, add an ability to use registered connections (or pools,
which is even better):

pgsql:connect(Name, Host, Port)

and then

pgsql:execute(Name, .....)

==========================================

Here are some more thoughts:

1. It's kind of weird that you use such a sequence:

{ok, C} = pgsql_sock:start_link(),
pgsql_sock:connect(C, Host, Port, ...)

It would be more consistent if you passed all the necessary parameters
into pgsql_sock:start_link and initiated the connection in
pgsql_sock:init/1, so it will look like:

{ok, Pid} = pgsql_sock:start_link(Options)

where Options is a proplist.

2. Using a proplist of options instead of listing these options (like
host and port) as mandatory parameters may be reasonable.

3. It might be a good idea to use macros for default values (like
timeouts, port number and so on).

4. I'd also consolidate pgsql_binary and pgsql_wire modules. Probably,
also moved the functions with binary pattern matchings from pgsql_sock
too. After all, the entire purpose is to describe the PostgreSQL
protocol and it might be more convenient if it's handled by a single
module.

P.S. Sometimes I so hate that the 'query' atom is reserved...

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



-- 
Best regards,
Dmitry Demeshchuk



More information about the erlang-questions mailing list