【问题标题】:Passing args to rails dbconsole将 args 传递给 rails dbconsole
【发布时间】:2016-07-12 00:40:35
【问题描述】:

rails dbconsole 检测到本地 DB 客户端并使用所有正确的凭据和传递的参数加载它。有没有办法将额外的参数传递给 DB 客户端?

例如,如果您使用 mysql,它将加载 mysql 客户端。我希望能够传递 mysql -e 'SELECT NOW();' 之类的参数或任何我想要的自定义查询。

【问题讨论】:

    标签: mysql ruby-on-rails ruby-on-rails-4


    【解决方案1】:

    不,你问的是不可能的。你可以通过一些选项,检查

    $ rails dbconsole -h
    Usage: rails dbconsole [environment] [options]
    -p, --include-password           Automatically provide the password from database.yml
        --mode [MODE]                Automatically put the sqlite3 database in the specified mode (html, list, line, column).
        --header
    -h, --help                       Show this help message.
    -e, --environment=name           Specifies the environment to run this console under (test/development/production).
                                     Default: development
    

    【讨论】:

    • 希望这不会在几个月/几年内成为答案。看来我需要向该项目提交 PR。 :)
    【解决方案2】:

    你问的不是完全可能的!

    echo -e "SELECT NOW();\n" | rails dbconsole
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多