NAME

    Mojolicious::Plugin::Nour::Database - Adds an easy to use database
    handle to your mojo app.

VERSION

    version 0.09

USAGE

    Somewhere in your startup routine, include something like this:

        $self->plugin( 'Mojolicious::Plugin::Nour::Database' );

    Then from your controllers, you can do things like this:

        sub list {
            my $self = shift;
            my $list = $self->db->query( qq|
                select l.language_code id
                     , l.unicode name_unicode
                     , l.english name_english
                     , l.direction
                  from content.resource r
                  join i18n.language l using ( language_code )
                 group by l.language_code, l.unicode, l.english, l.direction
                 order by l.language_code
            | )->hashes;
            $self->render( json => $list );
        }

    Or:

        sub list {
            my $self = shift;
            my $list = $self->db( 'audio' )->query( qq|
                select r.reciter_id id
                     , concat( 'http://audio.quran.com:9999/', r.path, '/ogg/' ) base_url
                     , r.arabic name_arabic
                     , r.english name_english
                  from audio.reciter r
                 order by r.english
            | )->hashes;
            $self->render( json => $list );
        }

    This module uses Nour::Database which is a wrapper for DBIx::Simple to
    provide an app helper that let's you easily query your databases and
    get the resultsets you want without having to deal with bloated,
    retarded ORMs. SQL is good for you. It also uses Nour::Config to read
    your db configuration. See the configuration section for details on how
    to set that up.

CONFIGURATION

    First, cursorily scan "USAGE" in Mojolicious::Plugin::Nour::Config
    because it's relevant in that you should put your configuration under a
    directory structure that might look like this, for example:

         $ find ./config/
        ./config/
        ./config/application
        ./config/application/nested
        ./config/application/nested/example.yml
        ./config/application.yml
        ./config/database
        ./config/database/private
        ./config/database/private/production.yml
        ./config/database/private/README.md
        ./config/database/config.yml

    The only real file you need is ./config/database/config.yml. Overriding
    configuration in the "private" sub-directory e.g.
    ./config/database/private/ is just a neat feature which let's you
    override the entire config or just a single nested key/value that was
    imported from the "public" configuration i.e.
    ./config/database/config.yml. Why is this useful? You can `echo
    '*private*' >> .gitignore` and ensure that your passwords or sensitive
    tokens or what not don't get exposed in your public git repository.

 CONFIGURATION EXAMPLES

    Here's a couple examples of what ./config/database/config.yml might
    look like:

    Postgresql

          ---
          development:
              dsn: dbi:Pg:dbname=foo;host=bar
              username: foobar
              password: barbaz
          production:
              dsn: dbi:Pg:dbname=bar
          default:
              database: production
              username: barfoo
              password: baroo
              option:
                  AutoCommit: 1
                  RaiseError: 1
                  PrintError: 1
                  pg_bool_tf: 0
                  pg_enable_utf8: 1

    MySQL

          ---
          development:
              dsn: dbi:mysql:database=app_dev;host=10.0.1.99
          production:
              dsn: dbi:mysql:database=app_prod;host=10.0.1.99
          production_with_drop_priv:
              dsn: dbi:mysql:database=app_prod;host=10.0.1.99
              username: drop
              password: drop
          otherdb:
              dsn: dbi:mysql:database=dbfoo;host=otherhost
              option:
                  AutoCommit: 0
          default:
              database: production
              username: ding
              password: dong
              option:
                  AutoCommit: 1
                  RaiseError: 1
                  PrintError: 1
                  mysql_enable_utf8: 1
                  mysql_auto_reconnect: 1

SEE ALSO

    Nour::Config

    Nour::Database

    DBIx::Simple

    Mojolicious::Plugin::Nour::Config

SUPPORT

 Bugs / Feature Requests

    Please report any bugs or feature requests through the issue tracker at
    https://github.com/sharabash/mojolicious-plugin-nour-database/issues.
    You will be notified automatically of any progress on your issue.

 Source Code

    This is open source software. The code repository is available for
    public review and contribution under the terms of the license.

    https://github.com/sharabash/mojolicious-plugin-nour-database

      git clone git://github.com/sharabash/mojolicious-plugin-nour-database.git

AUTHOR

    Nour Sharabash <amirite@cpan.org>

CONTRIBUTOR

    Nour Sharabash <nour.sharabash@gmail.com>

COPYRIGHT AND LICENSE

    This software is copyright (c) 2014 by Nour Sharabash.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.