Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how my own database handles use config.yml #50

Open
chenjch opened this issue Jan 27, 2014 · 3 comments
Open

how my own database handles use config.yml #50

chenjch opened this issue Jan 27, 2014 · 3 comments

Comments

@chenjch
Copy link

chenjch commented Jan 27, 2014

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
Copy link
Author

chenjch commented Jan 27, 2014

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

@msouth
Copy link

msouth commented Mar 5, 2014

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

@chenjch
Copy link
Author

chenjch commented Jun 11, 2014

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:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants