gadget 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gadget.rb +15 -3
  3. data/lib/gadget/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a24920c2e0dfbd4e9be5d21f3cbb358028612402
4
- data.tar.gz: a7add1ba201f2f2084e445255f395ebc0b8ade54
3
+ metadata.gz: ece84105a691b5880948bbeac5dcb229ba654aa6
4
+ data.tar.gz: 4fc8cc56f871fdcb5c471a50a8a9a39295375b7d
5
5
  SHA512:
6
- metadata.gz: 41656df40068edc50de39fdad9dcc099be8179cc5a028618a03b8047d75f3abcf599aac8fed2105f89386e20213b54430df14ff864f7295e1bf9ebc568a4f863
7
- data.tar.gz: 6ffc8664913c5a759e5580cc01226a4f1ccd87d257498740c10d094165baa1f8ca52cbc195a466a6e75f41e181374e8ac7c907b405ccc5530f097abf86b2a8cf
6
+ metadata.gz: b18de42940505918186b4622d7e1cac13cd0e55b03b0cd687a634dc6267c2899ee6a3032593c998f3890565be16d94d7989daf6cdefbb19dc2ee6ff6ee3666e6
7
+ data.tar.gz: 92381cb642b34f08e841335f4c7bf4fcbcdc9607a811f7dc02385f12e61948bfb4a5b34ed8d6bb07e5273f28ef82d9b1fd50bcf914f61f8ca55e51f45f0dd6a9
@@ -43,7 +43,7 @@ WHERE a.attnum >= 0
43
43
 
44
44
  def self.foreign_keys(conn, tablename = nil)
45
45
  sql = <<-END_OF_SQL
46
- SELECT t1.tablename AS tablename, t2.tablename AS refname
46
+ SELECT t1.tablename AS tablename, pg_constraint.conkey as cols, t2.tablename AS refname, pg_constraint.confkey as refcols
47
47
  FROM pg_constraint
48
48
  INNER JOIN pg_class c1 ON pg_constraint.conrelid=c1.oid
49
49
  INNER JOIN pg_tables t1 ON c1.relname=t1.tablename
@@ -59,7 +59,19 @@ AND pg_constraint.contype='f'
59
59
  sql += " AND t1.tablename=$1"
60
60
  rs = conn.exec_params(sql, [ tablename ])
61
61
  end
62
- tuples = rs.reduce({}) { | h, row | h[row['tablename']] ||= { :refs => [] }; h[row['tablename']][:refs] << row['refname']; h }
62
+ tuples = rs.reduce({}) do | h, row |
63
+ name = row['tablename']
64
+ h[name] ||= { :refs => [] }
65
+ col_names = self.columns(conn, name)[name][:columns]
66
+ refcol_names = self.columns(conn, row['refname'])[row['refname']][:columns]
67
+ new_ref = {
68
+ :cols => row['cols'].sub(/\A\{|\}\z/, '').split(',').map { | idx | col_names[idx.to_i - 1] },
69
+ :refname => row['refname'],
70
+ :refcols => row['refcols'].sub(/\A\{|\}\z/, '').split(',').map { | idx | refcol_names[idx.to_i - 1] },
71
+ }
72
+ h[name][:refs] << new_ref
73
+ h
74
+ end
63
75
  rs.clear
64
76
  tuples
65
77
  end
@@ -71,7 +83,7 @@ AND pg_constraint.contype='f'
71
83
  h[tablename] = []
72
84
  refs = foreign_keys[tablename]
73
85
  unless refs.nil?
74
- refs[:refs].each { | ref | h[tablename] << ref }
86
+ refs[:refs].each { | ref | h[tablename] << ref[:refname] }
75
87
  end
76
88
  h
77
89
  end
@@ -1,3 +1,3 @@
1
1
  module Gadget
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
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.0.2
4
+ version: 0.1.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: 2014-01-27 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg