Open knutov opened 12 years ago
Sorry for the huge delay responding to this.
I agree this would be quite useful.
I could add a default section, or have the code that fetches settings for a connection by name first take the settings from the "default" connection, then override them with the specific details specified in the named connection's settings - that might perhaps lead to even more readable config, e.g.:
plugins:
Database:
handle_class: 'Dancer::Plugin::Database::KISS'
driver: 'mysql'
database: '...'
host: '...'
port: 3306
username: '...'
password: '..'
connection_check_threshold: 300
dbi_params:
RaiseError: 1
AutoCommit: 1
mysql_auto_reconnect: 1
mysql_enable_utf8: 1
on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" ]
log_queries: 1
connections:
one:
host: '...'
username: '...'
password: '...'
In the example above, database()
would give you a handle using all the default settings; what you'd get from database('one')
would be a handle using exactly the same settings, except with the hostname, username & password overriden by the ones in that named connection's config.
The problem with this approach, though, is that it's a potentially surprising change of behaviour which could bite people already using the module, who don't expect settings declared for the default connection to be inherited.
So, given more thought, your suggestion of a defaults
key in the config may be safer.
Like both. Probably we can use the second and add some code to warn the users...
part of the real config:
Not good. Not readable. A lot of duplicated characters.
May be it's better to make
default:
section in config like this?