bigpresh / Dancer-Plugin-Database

Dancer::Plugin::Database - easy database support for Dancer applications
http://search.cpan.org/dist/Dancer-Plugin-Database
37 stars 36 forks source link

how my own database handles use config.yml #50

Open chenjch opened 10 years ago

chenjch commented 10 years ago

I use my own database handles, subclass from Dancer::Plugin::Database::Core::Handle, but i want to get some config setting from config.yml, such as:


plugins:
  Database:
    handle_class: 'Mew::DBHandle'
    driver: mysql
    host: ...
    ...
    log_queries: 1
    sql_abstract:
      limit_dialect: 'LimitXY'
      quote_char: '`'
      name_sep: '.'

at Dancer::Plugin::Database::Core, you give log_queries config to Dancer::Plugin::Database::Core::Handle, but how you give other config to my own handle


    # Indicate whether queries generated by quick_query() etc in
    # Dancer::Plugin::Database::Core::Handle should be logged or not; this seemed a
    # little dirty, but DBI's docs encourage it
    # ("You can stash private data into DBI handles via $h->{private_..._*}..")
    $dbh->{private_dancer_plugin_database} = {
        log_queries => $settings->{log_queries} || 0,
    };
chenjch commented 10 years ago

i just modify your code at present :) $dbh->{private_dancer_plugin_database} = { log_queries => $settings->{log_queries} || 0, sql_abstract => $settings->{sql_abstract} || {}, };

msouth commented 10 years ago

Would #38 do what you need, if it was accepted?

chenjch commented 10 years ago

config.yml


plugins:
  Database:
    handle_class: 'Mew::DBHandle'
    driver: mysql
    host: ...
    database: ..
    port: 3306
    ...
    handle_setting:
      log_queries: 1
      sql_abstract:
        limit_dialect: 'LimitXY'
        quote_char: '`'
        name_sep: '.'
Dancer::Plugin::Database::Core

$dbh->{private_dancer_plugin_database} = $settings->{handle_setting};
my own handle class Mew::DBHandle, subclass of Dancer::Plugin::Database::Core::Handle can get the sql_abstract setting by $self->{private_dancer_plugin_database}->{sql_abstract} and Dancer::Plugin::Database::Core::Handle can get the log_queries setting by $self->{private_dancer_plugin_database}->{log_queries}, this is my need and it looks like perfect:)