• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Perl
  • License
    Artistic License 2.0
  • Created about 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mojolicious ❤️ PostgreSQL

Mojo::Pg

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!

More Repositories

1

mojo

✨ Mojolicious - Perl real-time web framework
Perl
2,656
star
2

mojo.js

🦄 The Mojolicious real-time web framework for Node.js
JavaScript
484
star
3

minion

🐙 Perl high performance job queue
Perl
223
star
4

mojolicious.org

🍪 Mojolicious Website
CSS
32
star
5

mojo-assetpack

🚜 Compress and convert CSS, Less, Sass and JavaScript files
Perl
30
star
6

mojo-status

🐳 Mojolicious server status
Perl
29
star
7

Mojo-AsyncAwait

🙀 An Async/Await implementation for Mojolicious
Perl
21
star
8

dom.js

🔮 A fast and very small HTML/XML DOM parser with CSS selectors
JavaScript
20
star
9

pg.js

mojo.js ❤️ PostgreSQL
JavaScript
15
star
10

minion.js

🐎 Node.js high performance job queue
JavaScript
14
star
11

vscode-mojo

🔧 VS Code support for Mojolicious
14
star
12

path.js

🏕️ Convenient container class for file system paths.
TypeScript
12
star
13

template.js

⚡ A very fast embedded JavaScript template engine
JavaScript
11
star
14

server-starter

💫 Superdaemon
JavaScript
8
star
15

sql-abstract-pg

🐘 PostgreSQL features for SQL::Abstract
Perl
5
star
16

mojo-plugin-ejs

🚧 mojo.js plugin example
JavaScript
5
star
17

mojo-plugin-nunjucks

🚧 mojo.js plugin example (TypeScript)
TypeScript
3
star
18

mojojs.org

💥 mojo.js website
CSS
3
star
19

create-full-app

🐰 Create a full mojo.js app
JavaScript
3
star
20

sql.js

🏗️ Safely generate SQL statements with tagged template literals
JavaScript
3
star
21

vscode-mojo.js

🎭 VS Code support for mojo.js
2
star
22

create-lite-app

🐭 Create a single file mojo.js app
JavaScript
2
star
23

mojo-plugin-middleware

🪂 Express.js middleware support for mojo.js
1
star
24

user-agent.js

Experimental next gen user-agent
JavaScript
1
star
25

util.js

🔨 Just some utilities
JavaScript
1
star