Class: PgMeta::Column
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Default value.
-
#dimensions ⇒ Object
readonly
Number of dimensions if an array, 0 if not.
-
#element_type ⇒ Object
readonly
Element type if type is an array and nil otherwise.
-
#ordinal ⇒ Object
readonly
Ordinal number of the column.
-
#type ⇒ Object
readonly
Type of the column.
Attributes inherited from Node
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare columns by table and ordinal.
-
#array? ⇒ Boolean
True if column is an array.
-
#generated? ⇒ Boolean
True if column is auto generated.
-
#identity? ⇒ Boolean
True if column is an identity column.
-
#initialize(table, name, ordinal, type, element_type, dimensions, default, is_identity, is_generated, is_nullable, is_updatable) ⇒ Column
constructor
A new instance of Column.
-
#kind? ⇒ Boolean
True if column is a single-column reference to another record and is of type varchar or text.
-
#nullable? ⇒ Boolean
True if column is nullable.
-
#primary_key? ⇒ Boolean
True if column is the single primary key of the table and false otherwise.
-
#primary_key_column? ⇒ Boolean
True is column is (part of) the primary key of the table.
-
#reference? ⇒ Boolean
True if column is referencing other records.
-
#references ⇒ Object
List of referential constraints that involve this column.
- #sid ⇒ Object
- #to_h ⇒ Object
-
#unique? ⇒ Boolean
True if column is unique (not that this information is not stored in the Column but in a table constraint).
-
#updatable? ⇒ Boolean
True if column is updatable.
Methods inherited from Node
#dump, #dump_value, #guid, #inspect, #to_s, #to_yaml, #uid
Constructor Details
#initialize(table, name, ordinal, type, element_type, dimensions, default, is_identity, is_generated, is_nullable, is_updatable) ⇒ Column
Returns a new instance of Column.
393 394 395 396 397 398 399 400 401 402 |
# File 'lib/pg_meta/meta.rb', line 393 def initialize( table, name, ordinal, type, element_type, dimensions, default, is_identity, is_generated, is_nullable, is_updatable) super(table, name) @type, @element_type, @dimensions, @ordinal, @default, @is_identity, @is_generated, @is_nullable, @is_updatable = type, element_type, dimensions, ordinal, default, is_identity, is_generated, is_nullable, is_updatable table.columns[name] = self end |
Instance Attribute Details
#default ⇒ Object (readonly)
Default value
336 337 338 |
# File 'lib/pg_meta/meta.rb', line 336 def default @default end |
#dimensions ⇒ Object (readonly)
Number of dimensions if an array, 0 if not
333 334 335 |
# File 'lib/pg_meta/meta.rb', line 333 def dimensions @dimensions end |
#element_type ⇒ Object (readonly)
Element type if type is an array and nil otherwise
330 331 332 |
# File 'lib/pg_meta/meta.rb', line 330 def element_type @element_type end |
#ordinal ⇒ Object (readonly)
Ordinal number of the column
324 325 326 |
# File 'lib/pg_meta/meta.rb', line 324 def ordinal @ordinal end |
#type ⇒ Object (readonly)
Type of the column
327 328 329 |
# File 'lib/pg_meta/meta.rb', line 327 def type @type end |
Instance Method Details
#<=>(other) ⇒ Object
Compare columns by table and ordinal. FIXME: Compare by schema too (and what’s with the ‘super’?)
411 412 413 414 415 416 417 |
# File 'lib/pg_meta/meta.rb', line 411 def <=>(other) if other.is_a?(Column) && table == other.table ordinal <=> other.ordinal else super end end |
#array? ⇒ Boolean
True if column is an array
351 |
# File 'lib/pg_meta/meta.rb', line 351 def array?() !@element_type.nil? end |
#generated? ⇒ Boolean
True if column is auto generated
342 |
# File 'lib/pg_meta/meta.rb', line 342 def generated?() @is_generated end |
#identity? ⇒ Boolean
True if column is an identity column
339 |
# File 'lib/pg_meta/meta.rb', line 339 def identity?() @is_identity end |
#kind? ⇒ Boolean
True if column is a single-column reference to another record and is of type varchar or text
377 378 379 380 381 382 |
# File 'lib/pg_meta/meta.rb', line 377 def kind?() @kind ||= references.size == 1 && references.first.referencing_columns.size == 1 && !references.first.referenced_columns.first.primary_key? end |
#nullable? ⇒ Boolean
True if column is nullable
345 |
# File 'lib/pg_meta/meta.rb', line 345 def nullable?() @is_nullable end |
#primary_key? ⇒ Boolean
True if column is the single primary key of the table and false otherwise. Always nil for tables with multiple primary keys
361 362 363 364 |
# File 'lib/pg_meta/meta.rb', line 361 def primary_key?() return nil if table.primary_key_columns.size != 1 table.table? && self == table.primary_key_column || false end |
#primary_key_column? ⇒ Boolean
True is column is (part of) the primary key of the table
367 |
# File 'lib/pg_meta/meta.rb', line 367 def primary_key_column?() table.table? && table.primary_key_columns.include?(self) end |
#reference? ⇒ Boolean
True if column is referencing other records. This includes columns in multi-column references
371 372 373 |
# File 'lib/pg_meta/meta.rb', line 371 def reference?() @reference ||= !references.empty? end |
#references ⇒ Object
List of referential constraints that involve this column
385 386 387 388 389 390 391 |
# File 'lib/pg_meta/meta.rb', line 385 def references @references ||= begin table.referential_constraints.values.select { |constraint| constraint.referencing_columns.include?(self) } end end |
#sid ⇒ Object
316 317 318 |
# File 'lib/pg_meta/meta.rb', line 316 def sid() @sid ||= "#{table.name}.#{name}" end |
#to_h ⇒ Object
404 405 406 407 408 |
# File 'lib/pg_meta/meta.rb', line 404 def to_h() attrs_to_h( :name, :ordinal, :type, :element_type, :dimensions, :default, :identity?, :generated?, :nullable?, :updatable?, :primary_key?, :reference?, :kind?) end |
#unique? ⇒ Boolean
True if column is unique (not that this information is not stored in the Column but in a table constraint)
355 356 357 |
# File 'lib/pg_meta/meta.rb', line 355 def unique?() table.unique_constraints.values.any? { |constraint| constraint.columns == [self] } end |
#updatable? ⇒ Boolean
True if column is updatable
348 |
# File 'lib/pg_meta/meta.rb', line 348 def updatable?() @is_updatable end |