Class: PgMeta::Table
Direct Known Subclasses
Instance Attribute Summary collapse
-
#check_constraints ⇒ Object
readonly
Hash of check constraints.
-
#columns ⇒ Object
readonly
Hash of columns.
-
#constraints ⇒ Object
readonly
Hash of all constraints.
-
#primary_key_columns ⇒ Object
readonly
List of primary key columns.
-
#primary_key_constraints ⇒ Object
readonly
List of primary key constraints (there is only one element).
-
#referential_constraints ⇒ Object
readonly
Hash of referential constraints.
-
#triggers ⇒ Object
readonly
Hash of triggers.
-
#unique_constraints ⇒ Object
readonly
Hash of unique constraints.
Attributes inherited from Node
Instance Method Summary collapse
-
#depending_tables ⇒ Object
List of tables that directly or indirectly depends on this table.
-
#depending_views ⇒ Object
List of views that directly or indirectly depends on this table.
-
#initialize(schema, name, is_insertable, is_typed) ⇒ Table
constructor
A new instance of Table.
-
#insertable? ⇒ Boolean
True if the table/view is insertable.
-
#materialized? ⇒ Boolean
True iff table is a materialized view.
-
#primary_key_column ⇒ Object
The primary key column.
-
#table? ⇒ Boolean
True iff table is a real table and not a view.
- #to_h ⇒ Object
-
#typed? ⇒ Boolean
True if the table/view is typed.
-
#view? ⇒ Boolean
True iff table is a view.
Methods inherited from Node
#dump, #dump_value, #guid, #inspect, #to_yaml, #uid
Constructor Details
#initialize(schema, name, is_insertable, is_typed) ⇒ Table
Returns a new instance of Table.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/pg_meta/meta.rb', line 221 def initialize(schema, name, is_insertable, is_typed) super(schema, name) @is_insertable = is_insertable @is_typed = is_typed @columns = {} @primary_key_column = :undefined @primary_key_columns = [] @constraints = {} @primary_key_constraints = [] @unique_constraints = {} @check_constraints = {} @referential_constraints = {} @triggers = {} @depending_tables_hash = {} @depending_views_hash = {} schema.tables[name] = self end |
Instance Attribute Details
#check_constraints ⇒ Object (readonly)
Hash of check constraints. Maps from constraint name to CheckConstraint object object
203 204 205 |
# File 'lib/pg_meta/meta.rb', line 203 def check_constraints @check_constraints end |
#columns ⇒ Object (readonly)
Hash of columns
173 174 175 |
# File 'lib/pg_meta/meta.rb', line 173 def columns @columns end |
#constraints ⇒ Object (readonly)
Hash of all constraints
191 192 193 |
# File 'lib/pg_meta/meta.rb', line 191 def constraints @constraints end |
#primary_key_columns ⇒ Object (readonly)
List of primary key columns
Note: Assigned by PrimaryKeyConstraint#initialize
188 189 190 |
# File 'lib/pg_meta/meta.rb', line 188 def primary_key_columns @primary_key_columns end |
#primary_key_constraints ⇒ Object (readonly)
List of primary key constraints (there is only one element)
194 195 196 |
# File 'lib/pg_meta/meta.rb', line 194 def primary_key_constraints @primary_key_constraints end |
#referential_constraints ⇒ Object (readonly)
Hash of referential constraints. Maps from constraint name to ReferentialConstraint object
207 208 209 |
# File 'lib/pg_meta/meta.rb', line 207 def referential_constraints @referential_constraints end |
#triggers ⇒ Object (readonly)
Hash of triggers. Maps from trigger name to Trigger object
210 211 212 |
# File 'lib/pg_meta/meta.rb', line 210 def triggers @triggers end |
#unique_constraints ⇒ Object (readonly)
Hash of unique constraints. Maps from constraint name to UniqueConstraint object. Note that because constraint names are unpredictable, you’ll most often use +unqiue_constraints.values?
199 200 201 |
# File 'lib/pg_meta/meta.rb', line 199 def unique_constraints @unique_constraints end |
Instance Method Details
#depending_tables ⇒ Object
List of tables that directly or indirectly depends on this table. Note that the tables are sorted by name to make testing in rspec easier
214 |
# File 'lib/pg_meta/meta.rb', line 214 def depending_tables() @depending_tables ||= @depending_tables_hash.keys.sort_by(&:uid) end |
#depending_views ⇒ Object
List of views that directly or indirectly depends on this table. This is the opposite of View#defining_tables. Note that the tables are sorted by name to make testing in rspec easier
219 |
# File 'lib/pg_meta/meta.rb', line 219 def depending_views() @depending_views ||= @depending_views_hash.keys.sort_by(&:uid) end |
#insertable? ⇒ Boolean
True if the table/view is insertable
167 |
# File 'lib/pg_meta/meta.rb', line 167 def insertable?() @is_insertable end |
#materialized? ⇒ Boolean
True iff table is a materialized view
164 |
# File 'lib/pg_meta/meta.rb', line 164 def materialized?() false end |
#primary_key_column ⇒ Object
The primary key column. nil if the table has multiple primary key columns
176 177 178 179 180 181 182 183 |
# File 'lib/pg_meta/meta.rb', line 176 def primary_key_column return @primary_key_column if @primary_key_column != :undefined if primary_key_columns.size == 1 @primary_key_column = primary_key_columns.first else @primary_key_column = nil end end |
#table? ⇒ Boolean
True iff table is a real table and not a view
158 |
# File 'lib/pg_meta/meta.rb', line 158 def table?() true end |
#to_h ⇒ Object
239 240 241 242 243 244 |
# File 'lib/pg_meta/meta.rb', line 239 def to_h attrs_to_h( :name, :table?, :view?, :materialized?, :insertable?, :typed?, :columns, :primary_key_columns, :constraints, :referential_constraints, :depending_tables, :depending_views, :triggers) end |
#typed? ⇒ Boolean
True if the table/view is typed
170 |
# File 'lib/pg_meta/meta.rb', line 170 def typed?() @is_typed end |
#view? ⇒ Boolean
True iff table is a view
161 |
# File 'lib/pg_meta/meta.rb', line 161 def view?() !table? end |