No description
This repository has been archived on 2026-08-22. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Sebastian Riedel fb28915fa5 Bump version
2020-01-30 11:35:03 +01:00
.github more consistent descriptions 2016-06-29 14:04:30 +02:00
examples more consistent example configurations 2018-08-18 18:47:26 +02:00
lib Bump version 2020-01-30 11:35:03 +01:00
t Use the latest version of perltidy 2019-11-19 00:40:55 +01:00
.gitattributes fix a few typos 2016-04-27 00:27:35 +02:00
.gitignore try a different variant 2017-04-23 16:19:34 +02:00
.perltidyrc Add .perltidyrc 2019-10-09 18:50:49 +02:00
.travis.yml test with Perl 5.26 too 2017-11-02 20:10:18 +01:00
Changes Bump version 2020-01-30 11:35:03 +01:00
LICENSE first commit 2014-10-03 06:45:39 +02:00
Makefile.PL Updated DBD::Pg requirement to 3.7.4 due to certain JSON features not working on older versions 2019-09-04 11:15:10 +02:00
MANIFEST.SKIP make sure not to include .DS_Store files anymore 2017-07-28 12:05:43 +02:00
README.md we use the mojolicious org now 2018-09-11 22:47:43 +02:00

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
app->pg->migrations->from_data->migrate;

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);
  });
};

app->start;
__DATA__

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

Installation

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

$ curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n Mojo::Pg

We recommend the use of a Perlbrew environment.

Want to know more?

Take a look at our excellent documentation!