I've mentioned last week that i was working on a little something to make 
using PostgreSQL with Mojolicious more fun.

    https://github.com/kraih/mojo-pg

It's still very much experimental, and support for migrations is missing. 
The idea is to embrace SQL, and make asynchronous queries super simple.

I'm intentionally using the word "asynchronous" here, because it is based 
on DBD::Pg, so all I/O operations are blocking, but it allows us to let the 
event loop do other work (like handling other HTTP requests) while we wait 
for long running queries. Since database connections usually have a very 
low latency, the performance with blocking I/O and asynchronous queries can 
be quite excellent.

It also has some other fun properties that i'm currently experimenting with.

    # Sequential but asynchronous
    my $db = $pg->db;
    $db->query('select * from table1' => sub {...});
    $db->query('select * from table2' => sub {...});

A DBD::Pg connection can only handle one query at a time, this includes 
asynchronous ones, so the example above would normally crash and burn. But 
Mojo::Pg currently puts the second query into a waiting list and will 
perform it on the same connection once the first query has been finished. 
The example below on the other hand uses two DBD::Pg connections to 
actually perform the queries concurrently.

    # Concurrent and asynchronous
    $pg->db->query('select * from table1' => sub {...});
    $pg->db->query('select * from table2' => sub {...});

Of course i couldn't resist mojo-ifying the API a bit, so there's 
Mojo::Collection objects too. :)

    $pg->db->query('select foo, baz from table3 where foo = ?', 
'bar')->hashes->map(sub { $->{baz} })->join->say;

I'm quite happy with the results so far, but it's still just an experiment 
for now.

--
sebastian

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to