Mojo-Pg 3.05

Mojolicious ♥ PostgreSQL

Homepage: http://mojolicious.org

Platform: CPAN

Language: Perl

License: Artistic-2.0

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

View on registry: https://metacpan.org/release/Mojo-Pg


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;
use Mojo::Pg;
use 5.20.0;
use experimental 'signatures';

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!

Releases

3.05 March 12, 2017
3.04 March 08, 2017
3.03 March 07, 2017
3.02 February 18, 2017
3.01 February 12, 2017
3.0 February 11, 2017
2.35 January 11, 2017
2.34 January 01, 2017
2.33 January 01, 2017
2.32 January 01, 2017
See all 71 releases

Project Statistics

SourceRank 11
Dependencies 4
Dependent projects 9
Dependent repositories 0
Total releases 71
Latest release
First release
Stars 58
Forks 30
Watchers 18
Contributors 3
Repo Size: 437 KB

Top Contributors See all

Sebastian Riedel Flavio Poletti Andrey Khozov

Something wrong with this page? Make a suggestion

Export .ABOUT file for this library

Last synced: 2017-03-14 01:02:52 UTC

Login to resync this project