Yancy::Backend::Pg - A backend for Postgres using Mojo::Pg
version 0.011
# yancy.conf { backend => 'pg://user:pass@localhost/mydb', collections => { table_name => { ... }, }, } # Plugin use Mojolicious::Lite; plugin Yancy => { backend => 'pg://user:pass@localhost/mydb', collections => { table_name => { ... }, }, };
This Yancy backend allows you to connect to a Postgres database to manage the data inside. This backend uses Mojo::Pg to connect to Postgres.
See Yancy::Backend for the methods this backend has and their return values.
The URL for this backend takes the form pg://<user>:<pass>@<host>:<port>/<db>.
pg://<user>:<pass>@<host>:<port>/<db>
Some examples:
# Just a DB pg:///mydb # User+DB (server on localhost:5432) pg://user@/mydb # User+Pass Host and DB mysql://user:pass@example.com/mydb
The collections for this backend are the names of the tables in the database.
So, if you have the following schema:
CREATE TABLE people ( id SERIAL, name VARCHAR NOT NULL, email VARCHAR NOT NULL ); CREATE TABLE business ( id SERIAL, name VARCHAR NOT NULL, email VARCHAR NULL );
You could map that schema to the following collections:
{ backend => 'pg://user@/mydb', collections => { People => { required => [ 'name', 'email' ], properties => { id => { type => 'integer', readOnly => 1, }, name => { type => 'string' }, email => { type => 'string' }, }, }, Business => { required => [ 'name' ], properties => { id => { type => 'integer', readOnly => 1, }, name => { type => 'string' }, email => { type => 'string' }, }, }, }, }
Mojo::Pg, Yancy
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2017 by Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Yancy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yancy
CPAN shell
perl -MCPAN -e shell install Yancy
For more information on module installation, please visit the detailed CPAN module installation guide.