gadget 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gadget.rb +45 -6
- data/lib/gadget/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c4ee82ad59af21e41af87425042ad51394fd412
|
4
|
+
data.tar.gz: 80aa411a7b0e3cad37dcd6b27f88dd8e31a85e82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bfca7af601de89b47c3111839ba5fcc88b7ca8d4b6721114fd29e4a25896147ac495372a280fef7901428d56c13211c097f993afd6b12b0a35bae5972f57125
|
7
|
+
data.tar.gz: 62dbac736ffa02902e9c4cf63183e79a9f83681e49cb0da8cee44b0736322152e526c5562765ae6ee63ceaf1bb833ee6571c995b600574bd20f33af6325fe2bf
|
data/lib/gadget.rb
CHANGED
@@ -17,7 +17,12 @@ module Gadget
|
|
17
17
|
|
18
18
|
def self.tables(conn)
|
19
19
|
rs = conn.exec("SELECT c.oid, t.tablename FROM pg_tables t INNER JOIN pg_class c ON c.relname=t.tablename WHERE t.schemaname='public' ORDER BY t.tablename")
|
20
|
-
tuples = rs.reduce({})
|
20
|
+
tuples = rs.reduce({}) do | h, row |
|
21
|
+
h[row['tablename']] = {
|
22
|
+
:oid => row['oid'].to_i,
|
23
|
+
}
|
24
|
+
h
|
25
|
+
end
|
21
26
|
rs.clear
|
22
27
|
tuples
|
23
28
|
end
|
@@ -36,7 +41,11 @@ WHERE a.attnum >= 0
|
|
36
41
|
sql += " AND t.tablename = $1"
|
37
42
|
rs = conn.exec_params(sql, [ tablename ])
|
38
43
|
end
|
39
|
-
tuples = rs.reduce({})
|
44
|
+
tuples = rs.reduce({}) do | h, row |
|
45
|
+
h[row['tablename']] ||= { :columns => [] }
|
46
|
+
h[row['tablename']][:columns] << row['attname']
|
47
|
+
h
|
48
|
+
end
|
40
49
|
rs.clear
|
41
50
|
tuples
|
42
51
|
end
|
@@ -155,27 +164,57 @@ WHERE t.schemaname = 'public'
|
|
155
164
|
|
156
165
|
def self.functions(conn)
|
157
166
|
rs = conn.exec(<<-END_OF_SQL)
|
158
|
-
SELECT p.oid, p.proname
|
167
|
+
SELECT p.oid, p.proname, p.proargtypes
|
159
168
|
FROM pg_catalog.pg_proc p
|
160
169
|
INNER JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid
|
161
170
|
WHERE n.nspname = 'public'
|
162
171
|
END_OF_SQL
|
163
172
|
|
164
|
-
tuples = rs.reduce({})
|
173
|
+
tuples = rs.reduce({}) do | h, row |
|
174
|
+
h[row['proname']] = {
|
175
|
+
:oid => row['oid'].to_i,
|
176
|
+
:arg_types => row['proargtypes'].split(/\s+/).map(&:to_i),
|
177
|
+
}
|
178
|
+
h
|
179
|
+
end
|
165
180
|
rs.clear
|
166
181
|
tuples
|
167
182
|
end
|
168
183
|
|
169
184
|
def self.triggers(conn)
|
170
185
|
rs = conn.exec(<<-END_OF_SQL)
|
171
|
-
SELECT tg.oid, tg.tgname, t.tablename
|
186
|
+
SELECT tg.oid, tg.tgname, t.tablename, p.proname
|
172
187
|
FROM pg_catalog.pg_trigger tg
|
173
188
|
INNER JOIN pg_catalog.pg_class c ON tg.tgrelid = c.oid
|
174
189
|
INNER JOIN pg_catalog.pg_tables t ON c.relname = t.tablename
|
190
|
+
INNER JOIN pg_catalog.pg_proc p ON tg.tgfoid = p.oid
|
175
191
|
WHERE tg.tgconstrrelid = 0
|
176
192
|
END_OF_SQL
|
177
193
|
|
178
|
-
tuples = rs.reduce({})
|
194
|
+
tuples = rs.reduce({}) do | h, row |
|
195
|
+
h[row['tgname']] = {
|
196
|
+
:oid => row['oid'].to_i,
|
197
|
+
:tablename => row['tablename'],
|
198
|
+
:functionname => row['proname'],
|
199
|
+
}
|
200
|
+
h
|
201
|
+
end
|
202
|
+
rs.clear
|
203
|
+
tuples
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.types(conn)
|
207
|
+
rs = conn.exec(<<-END_OF_SQL)
|
208
|
+
SELECT t.oid, t.typname
|
209
|
+
FROM pg_catalog.pg_type t
|
210
|
+
END_OF_SQL
|
211
|
+
|
212
|
+
tuples = rs.reduce({}) do | h, row |
|
213
|
+
h[row['typname']] = {
|
214
|
+
:oid => row['oid'].to_i,
|
215
|
+
}
|
216
|
+
h
|
217
|
+
end
|
179
218
|
rs.clear
|
180
219
|
tuples
|
181
220
|
end
|
data/lib/gadget/version.rb
CHANGED