{"action":"created","issue":{"url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/85","repository_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database","labels_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/85/labels{/name}","comments_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/85/comments","events_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/85/events","html_url":"https://github.com/bigpresh/Dancer-Plugin-Database/issues/85","id":164617862,"number":85,"title":"Documentation about Multiple Connections may be misleading","user":{"login":"jkeenan","id":96524,"avatar_url":"https://avatars.githubusercontent.com/u/96524?v=3","gravatar_id":"","url":"https://api.github.com/users/jkeenan","html_url":"https://github.com/jkeenan","followers_url":"https://api.github.com/users/jkeenan/followers","following_url":"https://api.github.com/users/jkeenan/following{/other_user}","gists_url":"https://api.github.com/users/jkeenan/gists{/gist_id}","starred_url":"https://api.github.com/users/jkeenan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkeenan/subscriptions","organizations_url":"https://api.github.com/users/jkeenan/orgs","repos_url":"https://api.github.com/users/jkeenan/repos","events_url":"https://api.github.com/users/jkeenan/events{/privacy}","received_events_url":"https://api.github.com/users/jkeenan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-08T21:14:28Z","updated_at":"2016-07-11T21:20:53Z","closed_at":null,"body":"Here is a situation where, when I think I am following the documentation correctly, I don't get the intended results -- and I don't know whether it's my ignorance/inexperience or the docs or some combination of the two.\r\n\r\nHere are three files which, to the best of my knowledge, produce a correctly working Dancer application.\r\n\r\n-- lib/mywebapp.pm \r\n```perl\r\npackage mywebapp;\r\nuse v5.10.1;\r\nuse Dancer2;\r\nuse Dancer2::Plugin::Database;\r\nuse Crypt::SaltedHash;\r\nuse Data::Dump;\r\n\r\nour $VERSION = '0.1';\r\nset session => 'Simple';\r\n\r\nhook before => sub {\r\n    if (!session('user') && request->dispatch_path !~ m{^/login}) {\r\n        forward '/login', { requested_path => request->dispatch_path };\r\n    }\r\n};\r\n\r\nget '/' => sub { return \"Home Page\"; };\r\n\r\nget '/login' => sub {\r\n    # Display a login page; the original URL they requested is available as\r\n    # param('requested_path'), so could be put in a hidden field in the form\r\n    template 'login', { path => param('requested_path') };\r\n};\r\n\r\npost '/login' => sub {\r\n    my $user_value = body_parameters->get('user');\r\n    my $pass_value = body_parameters->get('pass');\r\n    my $user = database->quick_select('users', { username => $user_value });\r\n\r\n    if (! $user) {\r\n        warning \"Failed login for unrecognised user $user_value\";\r\n        redirect '/login?failed=1';\r\n    }\r\n    else {\r\n        my $csh = Crypt::SaltedHash->new(algorithm => 'SHA-1');\r\n        $csh->add($user->{password});\r\n        my $salted = $csh->generate;\r\n        if (Crypt::SaltedHash->validate($salted, $pass_value)) {\r\n            debug \"Password correct\";\r\n            session user => $user;\r\n            redirect body_parameters->get('path') || '/';\r\n        }\r\n        else {\r\n            debug \"Login failed; password incorrect for: \" . $user_value;\r\n            redirect '/login?failed=1';\r\n        }\r\n    }\r\n};\r\n\r\nget '/logout' => sub {\r\n    app->destroy_session;\r\n};\r\n\r\nget '/hello' => sub {\r\n    return \"Hello World\\n\";\r\n};\r\n\r\nstart;\r\n```\r\n\r\n-- views/login.tt\r\n```html \r\n<html>\r\n  <head>\r\n    <title>Session and logging in</title>\r\n  </head>\r\n  <body>\r\n    <form action='/login' method='POST'>\r\n        User Name : <input type='text' name='user'/>\r\n        Password: <input type='password' name='pass' />\r\n\r\n        <!-- Put the original path requested into a hidden\r\n                   field so it's sent back in the POST and can be\r\n                   used to redirect to the right page after login -->\r\n        <input type='hidden' name='path' value='<% path %>'/>\r\n\r\n        <input type='submit' value='Login' />\r\n    </form>\r\n  </body>\r\n</html>\r\n```\r\n\r\n-- config.yml\r\n```yaml\r\nappname: \"mywebapp\"\r\nlayout: \"main\"\r\ncharset: \"UTF-8\"\r\ntemplate: \"simple\"\r\nplugins:\r\n    Database:\r\n        driver: 'Pg'\r\n        database: 'dancer_study'\r\n        host: 'localhost'\r\n        port: 5432\r\n        username: 'dancer_operator'\r\n        connection_check_threshold: 10\r\n        dbi_params:\r\n            RaiseError: 1\r\n            AutoCommit: 1\r\n            pg_enable_utf8: 1\r\n        on_connect_do: []\r\n        log_queries: 1\r\n        handle_class:\r\n```\r\n\r\nOf these three files we are here concerned only with ```config.yml```.  Note that the entries for ```driver``` and ```database``` are located underneath ```Database``` which is in turn located under ```plugins```.\r\n\r\nNow, as I read the documentation for Dancer2::Plugin::Database (https://metacpan.org/pod/Dancer2::Plugin::Database#DEFINING-MULTIPLE-CONNECTIONS), I believe that, in order to allow for multiple configurations in the future, I shoule be able to get the same results using a configuration like this:\r\n```yaml\r\nappname: \"mywebapp\"\r\nlayout: \"main\"\r\ncharset: \"UTF-8\"\r\ntemplate: \"simple\"\r\nplugins:\r\n    Database:\r\n        connections:\r\n            dancer:\r\n                driver: 'Pg'\r\n                database: 'dancer_study'\r\n        port: 5432\r\n        username: 'dancer_operator'\r\n        connection_check_threshold: 10\r\n        dbi_params:\r\n            RaiseError: 1\r\n            AutoCommit: 1\r\n            pg_enable_utf8: 1\r\n        on_connect_do: []\r\n        log_queries: 1\r\n        handle_class:\r\n```\r\nHowever, when I try to run this app, I get these failures:\r\n```\r\nError 500 - Internal Server Error\r\nRuntime Error\r\nCan't get a database connection without settings supplied!\r\nPlease check you've supplied settings in config as per the Dancer::Plugin::Database \r\ndocumentation at .../Dancer/Plugin/Database/Core.pm line 206.\r\n```\r\nThe relevant code (https://metacpan.org/source/AMBS/Dancer-Plugin-Database-Core-0.14/lib/Dancer/Plugin/Database/Core.pm#L205) is:\r\n```perl\r\n    if (!$settings->{dsn} && !$settings->{driver}) {\r\n        die \"Can't get a database connection without settings supplied!\\n\"\r\n            . \"Please check you've supplied settings in config as per the \"\r\n            . \"Dancer::Plugin::Database documentation\";\r\n    }\r\n```\r\nNow, the section on \"DEFINING MULTIPLE CONNECTIONS\" doesn't have anything to say about the ```dsn``` setting.  And I **thought** that I had set a ```driver``` setting under plugins -> Database -> connections -> dancer.\r\n\r\nCan anyone explain what's going wrong?\r\n\r\nThank you very much.\r\nJim Keenan"},"comment":{"url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/comments/231868917","html_url":"https://github.com/bigpresh/Dancer-Plugin-Database/issues/85#issuecomment-231868917","issue_url":"https://api.github.com/repos/bigpresh/Dancer-Plugin-Database/issues/85","id":231868917,"user":{"login":"bigpresh","id":54107,"avatar_url":"https://avatars.githubusercontent.com/u/54107?v=3","gravatar_id":"","url":"https://api.github.com/users/bigpresh","html_url":"https://github.com/bigpresh","followers_url":"https://api.github.com/users/bigpresh/followers","following_url":"https://api.github.com/users/bigpresh/following{/other_user}","gists_url":"https://api.github.com/users/bigpresh/gists{/gist_id}","starred_url":"https://api.github.com/users/bigpresh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigpresh/subscriptions","organizations_url":"https://api.github.com/users/bigpresh/orgs","repos_url":"https://api.github.com/users/bigpresh/repos","events_url":"https://api.github.com/users/bigpresh/events{/privacy}","received_events_url":"https://api.github.com/users/bigpresh/received_events","type":"User","site_admin":false},"created_at":"2016-07-11T21:20:53Z","updated_at":"2016-07-11T21:20:53Z","body":"With your `driver` and `database` params now under the named connection `dancer` in the config, calling just `database()` to get the \"default\" handle will no longer work - it needs to be called as `database('dancer')`.   In other words, `database()` with no connection name supplied will look for connection details under `config->{plugins}{Database}`, but `database($connection_name)` will look for connection details under `config->{plugins}{Database}{$connection_name}` - does that make sense?"}}
{"actor":{"display_login":"bigpresh"}}