diff --git a/Dancer1/Changes b/Dancer1/Changes index f14fa2cb..127b2cd0 100644 --- a/Dancer1/Changes +++ b/Dancer1/Changes @@ -1,5 +1,9 @@ Revision history for Dancer-Plugin-Database +2.14 2018-11-20 + [ ENHANCEMENTS ] + - added pre database connection hook + 2.13 2016-08-13 [ BUG FIXES ] - Require 0.16 of core library, as 0.15 had a bug in :( diff --git a/Dancer1/lib/Dancer/Plugin/Database.pm b/Dancer1/lib/Dancer/Plugin/Database.pm index e3923b25..fe18b622 100644 --- a/Dancer1/lib/Dancer/Plugin/Database.pm +++ b/Dancer1/lib/Dancer/Plugin/Database.pm @@ -16,7 +16,7 @@ Dancer::Plugin::Database - easy database connections for Dancer applications =cut -our $VERSION = '2.13'; +our $VERSION = '2.14'; my $settings = undef; @@ -42,7 +42,9 @@ register database => sub { register_hook(qw(database_connected database_connection_lost database_connection_failed - database_error)); + database_error + database_connection_new + )); register_plugin; @@ -314,6 +316,12 @@ to connect (as obtained from the config file). Called when a database error is raised by C. Receives two parameters: the error message being returned by DBI, and the database handle in question. +=item C + +Called when a new database connection is about to be created. Receives a hashref of +connection settings as a parameter, containing the settings the plugin will be using +to connect (as obtained from the config file). + =back If you need other hook positions which would be useful to you, please feel free diff --git a/Dancer2/Changes b/Dancer2/Changes index 09bbd38d..6e52f8a4 100644 --- a/Dancer2/Changes +++ b/Dancer2/Changes @@ -1,5 +1,9 @@ Revision history for Dancer2-Plugin-Database +2.17 2018-11-20 + [ ENHANCEMENTS ] + - added pre database connection hook + 2.17 2016-08-13 [ BUG FIXES ] diff --git a/Dancer2/lib/Dancer2/Plugin/Database.pm b/Dancer2/lib/Dancer2/Plugin/Database.pm index 43a45592..c4068b85 100644 --- a/Dancer2/lib/Dancer2/Plugin/Database.pm +++ b/Dancer2/lib/Dancer2/Plugin/Database.pm @@ -16,12 +16,13 @@ Dancer2::Plugin::Database - easy database connections for Dancer2 applications =cut -our $VERSION = '2.17'; +our $VERSION = '2.18'; register_hook qw(database_connected database_connection_lost database_connection_failed - database_error); + database_error + database_connection_new); my $settings = {}; @@ -343,6 +344,12 @@ to connect (as obtained from the config file). Called when a database error is raised by C. Receives two parameters: the error message being returned by DBI, and the database handle in question. +=item C + +Called when a new database connection is about to be created. Receives a hashref of +connection settings as a parameter, containing the settings the plugin will be using +to connect (as obtained from the config file). + =back If you need other hook positions which would be useful to you, please feel free diff --git a/Shared/Changes b/Shared/Changes index 1b8bc589..7ed57422 100644 --- a/Shared/Changes +++ b/Shared/Changes @@ -1,5 +1,9 @@ Revision history for Dancer-Plugin-Database-Core +0.21 2018-11-20 + [ ENHANCEMENTS ] + - added hook for pre database connection + 0.20 2016-09-01 [ ENHANCEMENTS ] - Support "ILIKE" for Postgres users (Mario Duhanic) diff --git a/Shared/lib/Dancer/Plugin/Database/Core.pm b/Shared/lib/Dancer/Plugin/Database/Core.pm index 9207da8c..aaee8887 100644 --- a/Shared/lib/Dancer/Plugin/Database/Core.pm +++ b/Shared/lib/Dancer/Plugin/Database/Core.pm @@ -10,7 +10,7 @@ Dancer::Plugin::Database::Core - Shared core for D1 and D2 Database plugins =cut -our $VERSION = '0.20'; +our $VERSION = '0.21'; my %handles; # Hashref used as key for default handle, so we don't have a magic value that @@ -202,6 +202,7 @@ sub _set_defaults { sub _get_connection { my ($settings, $logger, $hook_exec) = @_; + $hook_exec->('database_connection_new', $settings); if (!$settings->{dsn} && !$settings->{driver}) { die "Can't get a database connection without settings supplied!\n" . "Please check you've supplied settings in config as per the "