pg_meta 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2d95868ebe3f4dbe52722b9866e20ee640d515c1767fa13e233f475b9034032
4
- data.tar.gz: 64b3e41000d62e4942a46e210335b5a5a119048d44cbf0cc0ececc5a22d118ab
3
+ metadata.gz: 41bfef6f94d3f36e05970e1e7894f7cbf31a5658d424186caa10deb6b14adc5d
4
+ data.tar.gz: 2c2b1e00874ee2d7c33ca83fd22a10a6367b21656ef0d4653a6289b3e2874814
5
5
  SHA512:
6
- metadata.gz: 8c55c5cea511bea40c15f2fc7021d83b6f0d4051593ce4a1ab8568d1e3c579605fdd54d6c262e9ae61425925bc51a0f680b791aaa2539986fa4918f47014682e
7
- data.tar.gz: 4d938cfa131bd81502a375360cecc68107913fbeda4905b7636f06d9e2be78091419e023449f0abb88636ce0446bb78b0583a423708a1f425c229eddeb2ccd8b
6
+ metadata.gz: c7815f55fea97137928df544fb2456ab4c7aa10e4eee0727491ed18904c63ed9c48c4a024e56db48e5c669b9e6c3fecb83bcfacb13ff6a0dfe8bd8eb57a4a0b3
7
+ data.tar.gz: 022334e098b1f5cd42ea2a503421a46c5ced08637ff4d50414e9e77e8b482fac9fe976b5e507224828b4ae0fc9e2dba46e1559b8b5d7332a7197e8db9cbd10e3
data/lib/pg_meta/meta.rb CHANGED
@@ -2,20 +2,28 @@ require 'yaml'
2
2
 
3
3
  module PgMeta
4
4
  class Node
5
- # Database object. Equal to self for Database objects
5
+ # Database object. Equal to self for Database objects. TODO: Rename 'database'
6
6
  attr_reader :root
7
7
 
8
8
  # Parent object. nil for Database objects
9
9
  attr_reader :parent
10
10
 
11
11
  # Unique name within parent context. This is usually what we understand as
12
- # the name of an object but functions have the full signature as "name"
12
+ # the name of an object but functions have the full signature as "name",
13
+ # eg. 'func(integer)'
13
14
  attr_reader :name
14
15
 
16
+ # Unique id within a schema. Only tables, columns, and functions have a sid
17
+ def sid()
18
+ @sid = nil
19
+ end
20
+
21
+ # Unique id within a database. The database object itself has a nil uid
15
22
  def uid()
16
23
  @uid ||= [parent.uid, name].compact.join(".")
17
24
  end
18
25
 
26
+ # Unique id within a RDBMS
19
27
  def guid()
20
28
  @guid ||= [parent.guid, name].compact.join(".")
21
29
  end
@@ -27,8 +35,9 @@ module PgMeta
27
35
  parent && parent.root.send(:add_node, self) # Add object to global database lookup
28
36
  end
29
37
 
30
- def to_h() raise StandardError, "Undefined method" end
31
- def to_yaml() to_h.to_yaml end
38
+ def to_s = name.to_s
39
+ def to_h = raise StandardError, "Undefined method"
40
+ def to_yaml = to_h.to_yaml
32
41
 
33
42
  def inspect() "#<#{self.class}:#{guid}>" end
34
43
 
@@ -134,6 +143,9 @@ module PgMeta
134
143
  database.schemas[name] = self
135
144
  end
136
145
 
146
+ # Lookup schema objects by sid
147
+ def [](sid) = database["#{uid}.#{sid}"]
148
+
137
149
  # True if schema is hidden. This can be set dynamically
138
150
  def hidden?() @hidden end
139
151
 
@@ -154,6 +166,8 @@ module PgMeta
154
166
  # Schema of the table
155
167
  alias_method :schema, :parent
156
168
 
169
+ alias_method :sid, :name
170
+
157
171
  # True iff table is a real table and not a view
158
172
  def table?() true end
159
173
 
@@ -182,6 +196,9 @@ module PgMeta
182
196
  end
183
197
  end
184
198
 
199
+ # Lookup column by name
200
+ def [](name) = @columns[name]
201
+
185
202
  # List of primary key columns
186
203
  #
187
204
  # Note: Assigned by PrimaryKeyConstraint#initialize
@@ -296,6 +313,10 @@ module PgMeta
296
313
  end
297
314
 
298
315
  class Column < Node
316
+ def sid()
317
+ @sid ||= "#{table.name}.#{name}"
318
+ end
319
+
299
320
  # Table of the column
300
321
  alias_method :table, :parent
301
322
 
@@ -495,6 +516,10 @@ module PgMeta
495
516
  end
496
517
 
497
518
  class Function < Node
519
+ def sid()
520
+ @sid ||= name
521
+ end
522
+
498
523
  # Schema of the function
499
524
  alias_method :schema, :parent
500
525
 
@@ -1,3 +1,3 @@
1
1
  module PgMeta
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2023-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: indented_io