File: README.md

package info (click to toggle)
libmojo-pg-perl 4.13-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 328 kB
  • sloc: perl: 695; sql: 11; makefile: 7
file content (55 lines) | stat: -rw-r--r-- 1,522 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

# Mojo::Pg [![Build Status](https://travis-ci.com/mojolicious/mojo-pg.svg?branch=master)](https://travis-ci.com/mojolicious/mojo-pg)

  A tiny wrapper around [DBD::Pg](https://metacpan.org/pod/DBD::Pg) that makes
  [PostgreSQL](https://www.postgresql.org) a lot of fun to use with the
  [Mojolicious](https://mojolicious.org) real-time web framework.

```perl
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](http://perlbrew.pl) environment.

## Want to know more?

  Take a look at our excellent
  [documentation](https://mojolicious.org/perldoc/Mojo/Pg)!