gadget 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +3 -3
- data/lib/gadget.rb +49 -49
- data/lib/gadget/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2336757dc9fef12e7744d993fbb108a8bf3d3442
|
4
|
+
data.tar.gz: fbc711006e1e72f29b9db1e2dce13966c8a0dd3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e6210284a15429d708ac4d79974a377c90385a382428f417e25df22e3dbc4281e39cea98b304cb565673e34c738b12515315d9761b3f68cfb1aa41231826d4e
|
7
|
+
data.tar.gz: 701f4bcd234770d80e5f7ffe880d085d8e94b902366a643c1b65491519b137f8692ad2f84cf7bb6ed86ed744dff174259ab538379a1f9cc95036ce344b3b4d9a
|
data/Rakefile
CHANGED
data/lib/gadget.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "pg"
|
4
|
+
require "tsort"
|
5
5
|
|
6
|
-
require
|
6
|
+
require "gadget/version"
|
7
7
|
|
8
8
|
## monkey patch Hash to gain .extractable_options?
|
9
9
|
class Hash
|
@@ -56,8 +56,8 @@ WHERE t.schemaname='public'
|
|
56
56
|
END_OF_SQL
|
57
57
|
rs = conn.exec(sql)
|
58
58
|
tuples = rs.reduce({}) do | h, row |
|
59
|
-
h[row[
|
60
|
-
:
|
59
|
+
h[row["tablename"]] = {
|
60
|
+
oid: row["oid"].to_i,
|
61
61
|
}
|
62
62
|
h
|
63
63
|
end
|
@@ -69,7 +69,7 @@ WHERE t.schemaname='public'
|
|
69
69
|
#
|
70
70
|
# ==== Usage
|
71
71
|
# columns = Gadget.columns(conn)
|
72
|
-
# columns_in_table = Gadget.columns(conn,
|
72
|
+
# columns_in_table = Gadget.columns(conn, "tablename")
|
73
73
|
#
|
74
74
|
# ==== Parameters
|
75
75
|
# * +conn+ - a +PG::Connection+ to the database
|
@@ -85,7 +85,7 @@ WHERE t.schemaname='public'
|
|
85
85
|
nspname = args.shift || "public"
|
86
86
|
|
87
87
|
sql = <<-END_OF_SQL
|
88
|
-
SELECT t.tablename, a.attname, ns.nspname
|
88
|
+
SELECT t.tablename, a.attnum, a.attname, ns.nspname
|
89
89
|
FROM pg_catalog.pg_attribute a
|
90
90
|
INNER JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
|
91
91
|
INNER JOIN pg_catalog.pg_tables t ON c.relname = t.tablename
|
@@ -104,8 +104,8 @@ AND ns.nspname = $1
|
|
104
104
|
rs = conn.exec_params(sql, [ nspname, tablename ])
|
105
105
|
end
|
106
106
|
tuples = rs.reduce({}) do | h, row |
|
107
|
-
h[row[
|
108
|
-
h[row[
|
107
|
+
h[row["tablename"]] ||= { columns: {} }
|
108
|
+
h[row["tablename"]][:columns][row["attnum"]] = row["attname"]
|
109
109
|
h
|
110
110
|
end
|
111
111
|
rs.clear
|
@@ -116,7 +116,7 @@ AND ns.nspname = $1
|
|
116
116
|
#
|
117
117
|
# ==== Usage
|
118
118
|
# fks = Gadget.foreign_keys(conn)
|
119
|
-
# fks_in_table = Gadget.foreign_keys(conn,
|
119
|
+
# fks_in_table = Gadget.foreign_keys(conn, "tablename")
|
120
120
|
#
|
121
121
|
# ==== Parameters
|
122
122
|
# * +conn+ - a +PG::Connection+ to the database
|
@@ -154,15 +154,15 @@ AND pg_constraint.contype = 'f'
|
|
154
154
|
rs = conn.exec_params(sql, [ tablename ])
|
155
155
|
end
|
156
156
|
tuples = rs.reduce({}) do | h, row |
|
157
|
-
name = row[
|
158
|
-
h[name] ||= { :
|
159
|
-
col_names = self.columns(conn, name, :
|
160
|
-
refcol_names = self.columns(conn, row[
|
157
|
+
name = row["tablename"]
|
158
|
+
h[name] ||= { refs: [] }
|
159
|
+
col_names = self.columns(conn, name, include_dropped: true)[name][:columns]
|
160
|
+
refcol_names = self.columns(conn, row["refname"], include_dropped: true)[row["refname"]][:columns]
|
161
161
|
new_ref = {
|
162
|
-
:
|
163
|
-
:
|
164
|
-
:
|
165
|
-
:
|
162
|
+
name: row["name"],
|
163
|
+
cols: row["cols"].sub(/\A\{|\}\z/, "").split(",").map { | attnum | col_names[attnum] },
|
164
|
+
ref_name: row["refname"],
|
165
|
+
ref_cols: row["refcols"].sub(/\A\{|\}\z/, "").split(",").map { | attnum | refcol_names[attnum] },
|
166
166
|
}
|
167
167
|
h[name][:refs] << new_ref
|
168
168
|
h
|
@@ -175,7 +175,7 @@ AND pg_constraint.contype = 'f'
|
|
175
175
|
#
|
176
176
|
# ==== Usage
|
177
177
|
# constraints = Gadget.constraints(conn)
|
178
|
-
# constraints_in_table = Gadget.constraints(conn,
|
178
|
+
# constraints_in_table = Gadget.constraints(conn, "tablename")
|
179
179
|
#
|
180
180
|
# ==== Parameters
|
181
181
|
# * +conn+ - a +PG::Connection+ to the database
|
@@ -213,26 +213,26 @@ WHERE t.schemaname = 'public'
|
|
213
213
|
rs = conn.exec_params(sql, [ tablename ])
|
214
214
|
end
|
215
215
|
tuples = rs.reduce({}) do | h, row |
|
216
|
-
name = row[
|
217
|
-
h[name] ||= { :
|
216
|
+
name = row["tablename"]
|
217
|
+
h[name] ||= { constraints: [] }
|
218
218
|
new_constraint = {
|
219
|
-
:
|
220
|
-
:
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
219
|
+
name: row["name"],
|
220
|
+
kind: case row["constrainttype"]
|
221
|
+
when "c"
|
222
|
+
"check"
|
223
|
+
when "f"
|
224
|
+
"foreign key"
|
225
|
+
when "p"
|
226
|
+
"primary key"
|
227
|
+
when "t"
|
228
|
+
"trigger"
|
229
|
+
when "u"
|
230
|
+
"unique"
|
231
|
+
when "x"
|
232
|
+
"exclusion"
|
233
|
+
else
|
234
|
+
%Q(*** unknown: "#{row["constrainttype"]}"")
|
235
|
+
end,
|
236
236
|
}
|
237
237
|
h[name][:constraints] << new_constraint
|
238
238
|
h
|
@@ -331,9 +331,9 @@ WHERE n.nspname = 'public'
|
|
331
331
|
END_OF_SQL
|
332
332
|
|
333
333
|
tuples = rs.reduce({}) do | h, row |
|
334
|
-
h[row[
|
335
|
-
:
|
336
|
-
:
|
334
|
+
h[row["proname"]] = {
|
335
|
+
oid: row["oid"].to_i,
|
336
|
+
arg_types: row["proargtypes"].split(/\s+/).map(&:to_i),
|
337
337
|
}
|
338
338
|
h
|
339
339
|
end
|
@@ -365,8 +365,8 @@ AND n.nspname = 'public'
|
|
365
365
|
END_OF_SQL
|
366
366
|
rs = conn.exec(sql)
|
367
367
|
tuples = rs.reduce({}) do | h, row |
|
368
|
-
h[row[
|
369
|
-
:
|
368
|
+
h[row["relname"]] = {
|
369
|
+
oid: row["oid"].to_i,
|
370
370
|
}
|
371
371
|
h
|
372
372
|
end
|
@@ -407,10 +407,10 @@ WHERE tg.tgconstrrelid = 0
|
|
407
407
|
rs = conn.exec_params(sql, [ tablename ])
|
408
408
|
end
|
409
409
|
tuples = rs.reduce({}) do | h, row |
|
410
|
-
h[row[
|
411
|
-
:
|
412
|
-
:
|
413
|
-
:
|
410
|
+
h[row["tgname"]] = {
|
411
|
+
oid: row["oid"].to_i,
|
412
|
+
table_name: row["tablename"],
|
413
|
+
function_name: row["proname"],
|
414
414
|
}
|
415
415
|
h
|
416
416
|
end
|
@@ -439,8 +439,8 @@ FROM pg_catalog.pg_type t
|
|
439
439
|
END_OF_SQL
|
440
440
|
|
441
441
|
tuples = rs.reduce({}) do | h, row |
|
442
|
-
h[row[
|
443
|
-
:
|
442
|
+
h[row["typname"]] = {
|
443
|
+
oid: row["oid"].to_i,
|
444
444
|
}
|
445
445
|
h
|
446
446
|
end
|
data/lib/gadget/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gadget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig S. Cottingham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.4.5.1
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Some methods for getting metadata and other deep details from a PostgreSQL
|