Closed jkeenan closed 8 years ago
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}{connections}
, but database($connection_name)
will look for connection details under config->{plugins}{Database}{connections}{$connection_name}
- does that make sense?
@bigpresh, thanks; that appears to have solved the problem. In lib/mywebapp.pm
(and, noting for reference, in lib/mywebapp/api.pm
), I have made this change:
diff --git a/lib/mywebapp.pm b/lib/mywebapp.pm
index 5d96325..124b075 100644
--- a/lib/mywebapp.pm
+++ b/lib/mywebapp.pm
@@ -30,7 +30,7 @@ get '/login' => sub {
post '/login' => sub {
my $user_value = body_parameters->get('user');
my $pass_value = url_decode(body_parameters->get('pass'));
- my $user = database->quick_select('users', { username => $user_value });
+ my $user = database('dancer')->quick_select('users', { username => $user_value });
if (! $user) {
warning "Failed login for unrecognised user $user_value";
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.
Here are three files which, to the best of my knowledge, produce a correctly working Dancer application.
-- lib/mywebapp.pm
-- views/login.tt
-- config.yml
Of these three files we are here concerned only with
config.yml
. Note that the entries fordriver
anddatabase
are located underneathDatabase
which is in turn located underplugins
.Now, 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:
However, when I try to run this app, I get these failures:
The relevant code (https://metacpan.org/source/AMBS/Dancer-Plugin-Database-Core-0.14/lib/Dancer/Plugin/Database/Core.pm#L205) is:
Now, the section on "DEFINING MULTIPLE CONNECTIONS" doesn't have anything to say about the
dsn
setting. And I thought that I had set adriver
setting under plugins -> Database -> connections -> dancer.Can anyone explain what's going wrong?
Thank you very much. Jim Keenan