bigpresh/Dancer-Plugin-Database

Multiple database connections unreliable?

bigpresh opened this issue · 4 comments

Reported on IRC by crayon:

15:44 Did you see my comment about Dancer::Plugin::Database from a couple days ago? There is something wierd with 1.0...
15:53 No - what's the issue?
15:53 Multiple database connections don't work well
15:54 When I have two, the first time it uses the connection it works, and then every other time it fails
15:54 It works fine in 0.90 though, which is the strange part
15:55 If add a 'my $settings;' in 'register database => sub {' it works in 1.0
15:55 but I have no idea why
15:56 Interesting - I'll take a look and see what's going on
15:57 Awesome, thanks.
16:01 Would you mind opening an issue on Github for it, to make it easier to track?
16:27 Sure, do it in an hour or so.

@crayon - if you happen to see this, do you have example code with which you've seen the problem?

I can reproduce this myself.

Looks like it's deleting named connections from the config after fetching them the first time. It doesn't look like it should do that, as it takes a copy to modify before returning, but it looks like it's actually getting a reference, and therefore modifying the original.

Will get this fixed ASAP and a new version out!

I've done some refactoring which appears to fix this issue, which I plan to test thoroughly tomorrow evening, then get a developer release out to CPAN.

In the process of working on this, I also added a quick_select() convenience method to Dancer::Plugin::Database::Handle, as that seemed to be a glaring omission. So, you can now say e.g.
my $row = database->quick_select($table_name, { id => $id });

Version 1.10 has just been released to CPAN, which should resolve this issue :)