Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mojolicious/mojo-pg
Mojolicious :heart: PostgreSQL
https://github.com/mojolicious/mojo-pg
mojolicious perl postgresql
Last synced: 3 days ago
JSON representation
Mojolicious :heart: PostgreSQL
- Host: GitHub
- URL: https://github.com/mojolicious/mojo-pg
- Owner: mojolicious
- License: artistic-2.0
- Created: 2014-10-03T04:43:40.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2022-03-23T17:08:34.000Z (almost 3 years ago)
- Last Synced: 2024-12-09T19:53:40.447Z (13 days ago)
- Topics: mojolicious, perl, postgresql
- Language: Perl
- Homepage: https://metacpan.org/release/Mojo-Pg
- Size: 777 KB
- Stars: 99
- Watchers: 32
- Forks: 46
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Mojo::Pg [![](https://github.com/mojolicious/mojo-pg/workflows/linux/badge.svg)](https://github.com/mojolicious/mojo-pg/actions)
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)!