Skip to content
Mojolicious ❤️ PostgreSQL
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github more consistent descriptions Jun 29, 2016
examples more consistent example configurations Aug 18, 2018
lib avoid modifying input data (closes #56) Feb 22, 2019
t run perltidy on SQL::Abstract::Pg and sql.t Jan 15, 2019
.gitignore try a different variant Apr 23, 2017
.travis.yml test with Perl 5.26 too Nov 2, 2017
Changes bump version Jan 20, 2019
LICENSE first commit Oct 3, 2014
MANIFEST.SKIP make sure not to include .DS_Store files anymore Jul 28, 2017
Makefile.PL use weak attributes when possible Oct 17, 2018

Mojo::Pg Build Status

A tiny wrapper around DBD::Pg that makes PostgreSQL a lot of fun to use with the Mojolicious real-time web framework.

use Mojolicious::Lite -signatures;
use Mojo::Pg;

helper pg => sub { state $pg = Mojo::Pg->new('postgresql://postgres@/test') };

# Use migrations to create a table during startup

get '/' => sub ($c) {

  my $db = $c->pg->db;
  my $ip = $c->tx->remote_address;

  # Store information about current visitor blocking
  $db->query('insert into visitors values (now(), ?)', $ip);

  # Retrieve information about previous visitors non-blocking
  $db->query('select * from visitors limit 50' => sub ($db, $err, $results) {

    return $c->reply->exception($err) if $err;

    $c->render(json => $results->hashes->to_array);


@@ migrations
-- 1 up
create table visitors (at timestamp with time zone, ip text);
-- 1 down
drop table visitors;


All you need is a one-liner, it takes less than a minute.

$ curl -L | perl - -M -n Mojo::Pg

We recommend the use of a Perlbrew environment.

Want to know more?

Take a look at our excellent documentation!

You can’t perform that action at this time.