Class: MetaDb::Table
Direct Known Subclasses
Instance Attribute Summary collapse
-
#primary_key_columns ⇒ Object
readonly
List of primary key columns.
-
#type ⇒ Object
readonly
Type of table.
Attributes inherited from DbObject
Instance Method Summary collapse
-
#columns ⇒ Object
List of columns.
-
#constraints ⇒ Object
List of constraints.
-
#initialize(schema, name, type, is_insertable, is_typed) ⇒ Table
constructor
A new instance of Table.
-
#insertable? ⇒ Boolean
True if the table/view is insertable.
-
#primary_key_column ⇒ Object
The primary key column.
-
#referential_constraints ⇒ Object
List of referential constraints.
-
#table? ⇒ Boolean
True iff table is a real table and not a view.
-
#triggers ⇒ Object
List of triggers.
-
#typed? ⇒ Boolean
True if the table/view is typed.
-
#view? ⇒ Boolean
True iff table is a view.
Methods inherited from DbObject
#<=>, #[], attrs, #dot, #dump, #dump_attrs, init, #inspect, #path
Constructor Details
#initialize(schema, name, type, is_insertable, is_typed) ⇒ Table
Returns a new instance of Table.
198 199 200 201 202 203 |
# File 'lib/meta_db/db_object.rb', line 198 def initialize(schema, name, type, is_insertable, is_typed) super(schema, name) @type, @is_insertable, @is_typed = type, is_insertable, is_typed @primary_key_column = :undefined @primary_key_columns = [] end |
Instance Attribute Details
#primary_key_columns ⇒ Object (readonly)
List of primary key columns
Note: Assigned by PrimaryKeyConstraint#initialize
183 184 185 |
# File 'lib/meta_db/db_object.rb', line 183 def primary_key_columns @primary_key_columns end |
#type ⇒ Object (readonly)
Type of table. Either ‘BASE TABLE’ or ‘VIEW’
153 154 155 |
# File 'lib/meta_db/db_object.rb', line 153 def type @type end |
Instance Method Details
#columns ⇒ Object
List of columns. Columns are sorted by ordinal
168 |
# File 'lib/meta_db/db_object.rb', line 168 def columns() @columns ||= constrain_children(MetaDb::Column).sort end |
#constraints ⇒ Object
List of constraints
186 187 188 |
# File 'lib/meta_db/db_object.rb', line 186 def constraints() @constraints ||= constrain_children(MetaDb::Constraint) end |
#insertable? ⇒ Boolean
True if the table/view is insertable
162 |
# File 'lib/meta_db/db_object.rb', line 162 def insertable?() @is_insertable end |
#primary_key_column ⇒ Object
The primary key column. nil if the table has multiple primary key columns
171 172 173 174 175 176 177 178 |
# File 'lib/meta_db/db_object.rb', line 171 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 |
#referential_constraints ⇒ Object
List of referential constraints
191 192 193 |
# File 'lib/meta_db/db_object.rb', line 191 def referential_constraints() @referential_constraints ||= constrain_children(MetaDb::ReferentialConstraint) end |
#table? ⇒ Boolean
True iff table is a real table and not a view
156 |
# File 'lib/meta_db/db_object.rb', line 156 def table?() true end |
#triggers ⇒ Object
List of triggers
196 |
# File 'lib/meta_db/db_object.rb', line 196 def triggers() @triggers ||= constrain_children(MetaDb::Trigger) end |
#typed? ⇒ Boolean
True if the table/view is typed
165 |
# File 'lib/meta_db/db_object.rb', line 165 def typed?() @is_typed end |
#view? ⇒ Boolean
True iff table is a view
159 |
# File 'lib/meta_db/db_object.rb', line 159 def view?() !table? end |