【发布时间】:2016-07-12 00:40:35
【问题描述】:
rails dbconsole 检测到本地 DB 客户端并使用所有正确的凭据和传递的参数加载它。有没有办法将额外的参数传递给 DB 客户端?
例如,如果您使用 mysql,它将加载 mysql 客户端。我希望能够传递 mysql -e 'SELECT NOW();' 之类的参数或任何我想要的自定义查询。
【问题讨论】:
标签: mysql ruby-on-rails ruby-on-rails-4
rails dbconsole 检测到本地 DB 客户端并使用所有正确的凭据和传递的参数加载它。有没有办法将额外的参数传递给 DB 客户端?
例如,如果您使用 mysql,它将加载 mysql 客户端。我希望能够传递 mysql -e 'SELECT NOW();' 之类的参数或任何我想要的自定义查询。
【问题讨论】:
标签: mysql ruby-on-rails ruby-on-rails-4
不,你问的是不可能的。你可以通过一些选项,检查
$ 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
【讨论】:
你问的不是完全可能的!
echo -e "SELECT NOW();\n" | rails dbconsole
【讨论】: