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
-
#[](name) ⇒ Object
Lookup column by name.
-
#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_s, #to_yaml, #uid
Constructor Details
#initialize(schema, name, is_insertable, is_typed) ⇒ Table
Returns a new instance of Table.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/pg_meta/meta.rb', line 238 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
220 221 222 |
# File 'lib/pg_meta/meta.rb', line 220 def check_constraints @check_constraints end |
#columns ⇒ Object (readonly)
Hash of columns
187 188 189 |
# File 'lib/pg_meta/meta.rb', line 187 def columns @columns end |
#constraints ⇒ Object (readonly)
Hash of all constraints
208 209 210 |
# File 'lib/pg_meta/meta.rb', line 208 def constraints @constraints end |
#primary_key_columns ⇒ Object (readonly)
List of primary key columns
Note: Assigned by PrimaryKeyConstraint#initialize
205 206 207 |
# File 'lib/pg_meta/meta.rb', line 205 def primary_key_columns @primary_key_columns end |
#primary_key_constraints ⇒ Object (readonly)
List of primary key constraints (there is only one element)
211 212 213 |
# File 'lib/pg_meta/meta.rb', line 211 def primary_key_constraints @primary_key_constraints end |
#referential_constraints ⇒ Object (readonly)
Hash of referential constraints. Maps from constraint name to ReferentialConstraint object
224 225 226 |
# File 'lib/pg_meta/meta.rb', line 224 def referential_constraints @referential_constraints end |
#triggers ⇒ Object (readonly)
Hash of triggers. Maps from trigger name to Trigger object
227 228 229 |
# File 'lib/pg_meta/meta.rb', line 227 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?
216 217 218 |
# File 'lib/pg_meta/meta.rb', line 216 def unique_constraints @unique_constraints end |
Instance Method Details
#[](name) ⇒ Object
Lookup column by name
200 |
# File 'lib/pg_meta/meta.rb', line 200 def [](name) = @columns[name] |
#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
231 |
# File 'lib/pg_meta/meta.rb', line 231 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
236 |
# File 'lib/pg_meta/meta.rb', line 236 def depending_views() @depending_views ||= @depending_views_hash.keys.sort_by(&:uid) end |
#insertable? ⇒ Boolean
True if the table/view is insertable
181 |
# File 'lib/pg_meta/meta.rb', line 181 def insertable?() @is_insertable end |
#materialized? ⇒ Boolean
True iff table is a materialized view
178 |
# File 'lib/pg_meta/meta.rb', line 178 def materialized?() false end |
#primary_key_column ⇒ Object
The primary key column. nil if the table has multiple primary key columns
190 191 192 193 194 195 196 197 |
# File 'lib/pg_meta/meta.rb', line 190 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
172 |
# File 'lib/pg_meta/meta.rb', line 172 def table?() true end |
#to_h ⇒ Object
256 257 258 259 260 261 |
# File 'lib/pg_meta/meta.rb', line 256 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
184 |
# File 'lib/pg_meta/meta.rb', line 184 def typed?() @is_typed end |
#view? ⇒ Boolean
True iff table is a view
175 |
# File 'lib/pg_meta/meta.rb', line 175 def view?() !table? end |