Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a2cb90c0
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a2cb90c0
编写于
11月 24, 2009
作者:
C
Carlhuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor script/dbconsole into an object
上级
d8c5ea76
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
90 addition
and
80 deletion
+90
-80
railties/lib/rails/commands/dbconsole.rb
railties/lib/rails/commands/dbconsole.rb
+89
-80
railties/lib/rails/generators/rails/app/templates/script/dbconsole
...lib/rails/generators/rails/app/templates/script/dbconsole
+1
-0
未找到文件。
railties/lib/rails/commands/dbconsole.rb
浏览文件 @
a2cb90c0
...
...
@@ -2,10 +2,16 @@
require
'yaml'
require
'optparse'
include_password
=
false
options
=
{}
module
Rails
class
DBConsole
def
self
.
start
new
.
start
end
OptionParser
.
new
do
|
opt
|
def
start
include_password
=
false
options
=
{}
OptionParser
.
new
do
|
opt
|
opt
.
banner
=
"Usage: dbconsole [options] [environment]"
opt
.
on
(
"-p"
,
"--include-password"
,
"Automatically provide the password from database.yml"
)
do
|
v
|
include_password
=
true
...
...
@@ -22,15 +28,15 @@
opt
.
parse!
(
ARGV
)
abort
opt
.
to_s
unless
(
0
..
1
).
include?
(
ARGV
.
size
)
end
end
env
=
ARGV
.
first
||
ENV
[
'RAILS_ENV'
]
||
'development'
unless
config
=
YAML
::
load
(
ERB
.
new
(
IO
.
read
(
Rails
.
root
+
"
/config/database.yml"
)).
result
)[
env
]
env
=
ARGV
.
first
||
ENV
[
'RAILS_ENV'
]
||
'development'
unless
config
=
YAML
::
load
(
ERB
.
new
(
IO
.
read
(
"
#{
Rails
.
root
}
/config/database.yml"
)).
result
)[
env
]
abort
"No database is configured for the environment '
#{
env
}
'"
end
end
def
find_cmd
(
*
commands
)
def
find_cmd
(
*
commands
)
dirs_on_path
=
ENV
[
'PATH'
].
to_s
.
split
(
File
::
PATH_SEPARATOR
)
commands
+=
commands
.
map
{
|
cmd
|
"
#{
cmd
}
.exe"
}
if
RUBY_PLATFORM
=~
/win32/
...
...
@@ -42,10 +48,10 @@ def find_cmd(*commands)
end
end
found
?
full_path_command
:
abort
(
"Couldn't find database client:
#{
commands
.
join
(
', '
)
}
. Check your $PATH and try again."
)
end
end
case
config
[
"adapter"
]
when
"mysql"
case
config
[
"adapter"
]
when
"mysql"
args
=
{
'host'
=>
'--host'
,
'port'
=>
'--port'
,
...
...
@@ -64,17 +70,17 @@ def find_cmd(*commands)
exec
(
find_cmd
(
'mysql'
,
'mysql5'
),
*
args
)
when
"postgresql"
when
"postgresql"
ENV
[
'PGUSER'
]
=
config
[
"username"
]
if
config
[
"username"
]
ENV
[
'PGHOST'
]
=
config
[
"host"
]
if
config
[
"host"
]
ENV
[
'PGPORT'
]
=
config
[
"port"
].
to_s
if
config
[
"port"
]
ENV
[
'PGPASSWORD'
]
=
config
[
"password"
].
to_s
if
config
[
"password"
]
&&
include_password
exec
(
find_cmd
(
'psql'
),
config
[
"database"
])
when
"sqlite"
when
"sqlite"
exec
(
find_cmd
(
'sqlite'
),
config
[
"database"
])
when
"sqlite3"
when
"sqlite3"
args
=
[]
args
<<
"-
#{
options
[
'mode'
]
}
"
if
options
[
'mode'
]
...
...
@@ -82,6 +88,9 @@ def find_cmd(*commands)
args
<<
config
[
'database'
]
exec
(
find_cmd
(
'sqlite3'
),
*
args
)
else
else
abort
"Unknown command-line client for
#{
config
[
'database'
]
}
. Submit a Rails patch to add support!"
end
end
end
end
\ No newline at end of file
railties/lib/rails/generators/rails/app/templates/script/dbconsole
浏览文件 @
a2cb90c0
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/dbconsole'
Rails::DBConsole.start
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录