forked from ebeigarts/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrailsrc
82 lines (72 loc) · 1.81 KB
/
railsrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def l!(stream = STDOUT)
if defined?(ActiveRecord::Base)
ActiveRecord::Base.logger = Logger.new(stream)
ActiveRecord::Base.connection.instance_variable_set(:@logger, ActiveRecord::Base.logger)
end
if defined?(Mongoid)
Mongoid.logger = Logger.new(stream)
end
if defined?(Moped)
Moped.logger = Logger.new(stream)
end
true
end
def nolog!
l! nil
end
def r!
reload!
end
def t(data, *fields)
if defined?(table)
if fields.empty?
table data
else
table data, :fields => fields
end
else
data
end
end
def arb
ActiveRecord::Base
end
def sql(query)
arb.connection.select_all(query)
end
def tsql(query)
t sql(query)
end
def explain(query)
arb.connection.explain(query)
end
def tdesc(name)
sql = <<-SQL
select
decode(column_id,0,TABLE_NAME,null) as TABLE_NAME,
decode(column_id,0,null,column_id) as COLUMN_ID,
COLUMN_NAME, NULLABLE, DATA_TYPE, COMMENTS
from (
select cc.TABLE_NAME,
tc.COLUMN_ID, tc.COLUMN_NAME,
tc.NULLABLE, tc.DATA_TYPE ||
case when tc.DATA_SCALE is not null then '(' || tc.DATA_PRECISION || ',' || tc.DATA_SCALE || ')'
when tc.DATA_PRECISION is not null then '(' || tc.DATA_PRECISION || ')'
when tc.DATA_LENGTH is not null and tc.DATA_TYPE like '%CHAR%' then '(' || tc.DATA_LENGTH || ')'
end DATA_TYPE,
cc.COMMENTS
from user_col_comments cc
INNER JOIN user_tab_cols tc ON (cc.TABLE_NAME = tc.TABLE_NAME and cc.TABLE_NAME = tc.TABLE_NAME and cc.COLUMN_NAME = tc.COLUMN_NAME)
UNION
select tab.table_name as TABLE_NAME,
0 as COLUMN_ID, '' as COLUMN_NAME,
'' as NULLABLE, '' as DATA_TYPE,
tab.comments as COMMENTS
from user_tab_comments tab
)
where table_name = UPPER('#{name}')
order by table_name, column_id
SQL
tsql sql
end
l!